tips:
example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/vue@3"></script>
<title>Document</title>
</head>
<body>
<div id="leo">
<input type="button" value="go" @click="change"/>
<div v-for="name of arr" :key="name.id" @click="go"> <!--元素中可以直接添加事件-->
{{name.value}}{{name.id}}
</div>
<span v-for="s in string" :key="index">
{{s}}
</span>
<br/>
<span v-for="n in 10">
{{n}}
</span>
<span v-for="m in 10" v-if="m==2?true:false"> <!--v-if的优先级要高于v-for-->
{{m}}
</span>
</div>
<script>
Vue.createApp({
data(){
return {
"string":"hello",
"arr":[
{
"value":"leo",
"id":0
},
{
"value":"sky",
"id":1
},
{
"value":"blue",
"id":2
}
]
}
},
"methods":{
change(){
this.arr.push({
"value":"busy",
"id":3
}),
this.string +="vue3"
},
go(){
alert(1)
}
}
}).mount("#leo")
</script>
</body>
</html>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。