动态绑定style:
html核心代码如下:
<div>
<h2 v-bind:style="getStyles()">{{message}}</h2>
</div>
script代码如下:
<script src="../Vue_js/vue.js"></script>
<script>
const app = new Vue ({
el: '#app',
data: {
message: '动态绑定style',
finalSize: 100,
finalColor: 'red',
},
methods: {
getStyles: function () {
return {fontSize: this.finalSize + 'px', backgroundColor: this.finalColor}
}
},
})
</script>