1.v-html和v-text的区别
v-html可解析标签;v-text正常文本输出;
<div id='app'>
<input type="text" v-model='msg'>
<p v-html='msg'>{{msg}}</p>
<h3 v-text='msg'>{{msg}}</h3>
</div>
<script src='js/vue.js'></script>
<script>
new Vue({
el:'#app',
data:{
msg:'今天周六,照常上课'
}
})
</script>
2.v-once和v-pre的区别
v-once只绑定一次;v-pre原样输出
<div id='app'>
<input type="text" v-model='msg'>
<a href="#" v-once>{{msg}}</a> <br>
<a href="#" v-pre>{{msg}}</a>
</div>
<script src='js/vue.js'></script>
<script>
new Vue({
el:'#app',
data:{
msg:'今天周六,照常上课'
}
})
</script>
3.vue的生命周期
使用v-cloak不显示未被编译的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
[v-cloak]{
display:none;
} //css样式
</style>
</head>
<body>
<div id='app'>
<h1 v-cloak>{{msg}}</h1> //需要隐藏的未被编译的代码,不被显示的元素中添加
</div>
<script src='js/vue.js'></script>
<script>
new Vue({
el:'#app',
data:{
msg:'hellovue'
},
beforeMount:function(){
alert(1111)
}
})
</script>
</body>
</html>
4.选项卡
<div id='app'>
<ul>
<li v-for="(value,index) in card" @click='chg(index)'>{{value.title}}</li>
</ul>
<ul>
<li v-for="(value,index) in card" v-show='value.flag'>{{value.content}}</li>
</ul>
</div>
<script src='vue.js'></script>
<script>
new Vue({
el:'#app',
data:{
card:[
{title:'选项卡1',content:'选项卡1选项卡1选项卡1选项卡1',flag:true},
{title:'选项卡2',content:'选项卡2选项卡2选项卡2选项卡2',flag:false},
{title:'选项卡3',content:'选项卡3选项卡3选项卡3选项卡3',flag:false}
]
},
methods:{
chg:function(ind){
for(var i=0;i<this.card.length;i++){
this.card[i].flag=false; //点击的时候执行,使true转化为falese
}
this.card[ind].flag=true; //点击的时候执行,使false转化为true
}
}
})
</script>
网友评论