感谢您的支持,我会继续努力的!
打开微信扫一扫,即可进行扫码打赏哦
点我查看本站打赏源码!
Powered by RUNCODEX.COM,学的不仅是技术,更是梦想!!!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runcodex.com)</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<div v-bind:style="{color: 'red', fontSize: size + 'px'}">可以动态调节</div>
<div v-bind:style="computedStyle">可以动态调节</div>
<div v-bind:style="objectStyle"> 可以动态调节</div>
<div v-bind:style="methodStyle()"> 可以动态调节</div>
{{size}}
<button @click="++size">+</button>
<button @click="--size">-</button>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
size: 20,
objectStyle: {
color: 'green',
fontSize: 20 + 'px' //this.size为undefined
}
},
methods:{
methodStyle: function(){
return {color: 'green', fontSize: this.size + 'px'} //失效,颜色也不会改变
computed: {
computedStyle: function(){
return {color: 'red' , fontSize: this.size + 'px'}
watch: {
size: function(){
this.objectStyle.fontSize = this.size + 'px'
})
</script>
</body>
</html>
输入 JavaScript 代码……
xxxxxxxxxx
输入 CSS 代码……