<style>
#d1{
color:red;
}
#d11{
color:blue;
}
.d1{
font-size: 50px;
}
</style>
const Counter={
data:function(){
return{
num:0,
uname:"张三",
msg:"<h2>标题</h2>",
id:"d1",
url:"https://img10.360buyimg.com/img/jfs/t1/192028/25/33459/5661/63fc2af2F1f6ae1b6/d0e4fdc2f126cbf5.png",
mouseevent:"click",
attributename:"id"
}
},
methods:{
changeuname: function(){
this.uname='李四'
},
changeColor: function(){
if(this.id == "d1")
{this.id = "d11"}
else
{this.id = "d1"}
}
}
}
let app =Vue.createApp(Counter).mount('#counter')
console.log(app);
<p>{{num}}</p>
<p>{{uname}}</p>
<p v-once>{{uname}}</p>
<p>{{msg}}</p>
- v-html指令,只对信任内容使用,不可对用户填入的值使用
<p v-html="msg"></p>
<button @click="changeuname">change user name</button>
<p v-bind:id="id">绑定id</p>
<img v-bind:src="url" alt="">
<button @click="changeColor">change color</button>
<button @click="id='d11'">change toBlue</button>
<p>{{num+1}}</p>
<p>{{uname.split('').reverse().join('')}}</p>
<p v-bind:id="id+1">绑定id</p>
<button @click="changeColor">v-on语法糖</button>
<button v-on:click="changeColor">change color</button>
<p :id="id">v-bind语法糖</p>
<p v-bind:id="id">绑定id</p>
<p v-bind:[attributename]="id">动态参数 </p>
<button @click="attributename='class'">改变属性</button>
<button @[mouseevent]="changeColor">被改变事件</button>
<button @click="mouseevent='mouseover'">主动改变事件</button>