css样式" background-position : center;“未命中,为什么?因为背景将覆盖背景位置
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="div1" :style="'background-position: center; height:200px;width:300px;background: url('+imgURL +')'"></div>
</body>
<script>
var vm = new Vue({
el: "#div1",
data: {
imgURL: 'https://www.baidu.com/img/bd_logo1.png'
}
});
</script>
</html>
发布于 2018-08-10 04:54:38
在您的CSS中,稍后将在规则中用background替换background-position。如果您将background更改为background-image,它将起作用。
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="div1" :style="'background-position: center; height:200px;width:300px;background-image: url('+imgURL +')'"></div>
</body>
<script>
var vm = new Vue({
el: "#div1",
data: {
imgURL: 'https://www.baidu.com/img/bd_logo1.png'
}
});
</script>
</html>
https://stackoverflow.com/questions/51773739
复制相似问题