基本指令
1.非表单元素(div p span)
优点 缺点 作用 {{}} 书写方便,简单,快捷 不能解析data数据中的标签,会出现闪屏问题 做插值表达式 v-html 可以解析data数据中的标签 – 做富文本渲染 v-text 不会出现闪屏问题 不能解析data数据中的标签 做标签内容展示
解决闪屏问题: v-cloak
通过v-cloak指令将制定元素设置样式display:none,当vue文件加载成功之后,再将带有v-cloak元素的样式设置为:display:block,
< style>
[v-cloak] {
display : none;
}
</ style>
< div id = " app" v-cloak >
< h2> name的值为:{{name}}</ h2>
< div> {{'拥有一辆:'+car}}</ div>
< div> 价格在:{{price.toFixed(2)}}万</ div>
< div> {{score>=60 ? score: 60}}</ div>
< p> {{1+1}}</ p>
< div> {{str}}</ div>
</ div>
<!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" >
< title> Document</ title>
< style>
[v-cloak] {
display : none;
}
</ style>
</ head>
< body>
< div id = " app" v-cloak >
< h2> name的值为:{{name}}</ h2>
< div> {{'拥有一辆:'+car}}</ div>
< div> 价格在:{{price.toFixed(2)}}万</ div>
< div> {{score>=60 ? score: 60}}</ div>
< p> {{1+1}}</ p>
< div> {{str}}</ div>
</ div>
< script>
new Vue ( {
el: '#app' ,
data: {
name: '赵丽颖' ,
car: '宝马X6' ,
price: 60.00 ,
score: 65 ,
str: '<mark>坐在宝马车里烫火锅</mark>'
}
} )
</ script>
</ body>
</ html>
<!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" >
< title> Document</ title>
</ head>
< body>
< div id = " app" >
< h2 v-html = " name" > 哈哈</ h2>
< div v-html = " str" > </ div>
</ div>
< script>
new Vue ( {
el: '#app' ,
data: {
name: '赵丽颖' ,
car: '宝马X6' ,
price: 60.00 ,
score: 65 ,
str: '<mark>坐在宝马车里烫火锅</mark>'
}
} )
</ script>
</ body>
</ html>
<!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" >
< title> Document</ title>
</ head>
< body>
< div id = " app" >
< h2 v-text = " name" > 哈哈</ h2>
< div v-text = " str" > </ div>
</ div>
< script>
new Vue ( {
el: '#app' ,
data: {
name: '赵丽颖' ,
car: '宝马X6' ,
price: 60.00 ,
score: 65 ,
str: '<mark>坐在宝马车里烫火锅</mark>'
}
} )
</ script>
</ body>
</ html>