Vue模板语法(一)
Vue模板语法 一
vue简介
1、vue插值
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue的插值案例</title>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li>
<h3>文本</h3>
{{msg}}
</li>
<li>
<h3>html标签渲染</h3>
<div v-html="htmlStr"></div>
</li>
<li>
<h3>v-bind属性绑定指令</h3>
未绑定:<input type="text" value="22" />
<!-- v-bind简写 : -->
v-bind绑定:<input type="text" :value="age" />
</li>
<li>
<h3>表达式</h3>
{{str.substr(0,6).toUpperCase()}}
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
<li v-bind:id="'list-' + id">我的Id是js动态生成的</li>
</li>
</ul>
</div> </body>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
msg: 'hello Vue!!',
htmlStr: '<span style="color: red;">红色小猪佩奇</span>',
age: 23,
str:'https://www.baidu.com',
number:6,
ok:true,
id:21,
},
})
</script> </html>

2、vue指令
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue的指令案例</title>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li>
<h3>分支</h3>
<div v-if="score>90">A</div>
<div v-else-if="score>80">B</div>
<div v-else-if="score>70">C</div>
<div v-else-if="score>60">D</div>
<div v-else="">E</div>
<input type="text" v-model="score" />
</li>
<li>
<h3>v-show指令</h3>
<div v-show="flag">出来吧!1</div>
<!-- 分清楚v-if跟v-show的区别
v-if:控制的是标签是否答应
v-show:控制的是标签的样式
-->
<div v-if="flag">出来吧!2</div>
</li>
<li>
<h3>v-for指令</h3>
<div v-for="item,index in data1">
{{item}}~{{index}}<br>
</div>
<hr />
<div v-for="item,index in data2">
{{item.id}}~{{item.name}}~{{index}}<br>
</div>
</li>
<li>
<h3>动态事件调用</h3>
<button v-on:[evname]="xxx">动态事件调用</button>
<input type="text" v-model="evname" />
</li>
</ul>
</div> </body>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
score: 88,
flag: true,
data1: [1, 3, 6, 9, 14],
data2: [{
id: 1,
name: '游戏'
},
{
id: 2,
name: '篮球'
},
{
id: 3,
name: '唱歌'
}],
evname:'click'
},
methods:{
xxx(){
console.log('xxx方法被调用')
}
}
})
</script> </html>

3、vue过滤器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue的过滤器案例</title>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li>
<h3>局部过滤器的注册</h3>
{{msg}}<br>
{{msg|a}}<br>
{{yuan|a}}
</li>
<li>
<h3>局部过滤器的串联</h3>
{{yuan|a|b}}<br>
</li>
<li>
<h3>全局过滤器的注册</h3>
{{yuan|c}}<br>
</li>
</ul>
</div> </body>
<script type="text/javascript">
Vue.filter('c',function(v){
console.log(v)
return v.substring(8,16);
}) new Vue({
el: "#app",
data: {
msg: 'https://www.baidu.com',
yuan:'https://www.yuan.com'
},
filters:{
// a是过滤器的名字,后面的函数是过滤器的作用
'a':function(v){
console.log(v)
return v.substring(0,18);
},
'b':function(v){
console.log(v)
return v.substring(5,14);
}
}
})
</script> </html>

4、计算属性监听属性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue的计算属性监听属性案例</title>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li>
<h3>计算属性</h3>
商品1
单价:<input v-model="price1" />
数量:<input v-model="num1" />
总价:{{total1}}<br />
商品2
单价:<input v-model="price2" />
数量:<input v-model="num2" />
总价:{{total2}}
<hr />
合计:{{count}} </li>
<li>
<h3>监听属性</h3>
km:<input v-model="km" />
m:<input v-model="m" />
</li>
</ul>
</div> </body>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
price1:16,
price2:20,
num1:1,
num2:1,
km:1,
m:1000
},
computed:{
total1(){
return parseInt(this.price1)*parseInt(this.num1);
},
total2(){
return parseInt(this.price2)*parseInt(this.num2);
},
count(){
return parseInt(this.total1)+parseInt(this.total2)
}
},
watch:{
km(v){
this.m=v*1000;
},
m(v){
this.km=v/1000;
}
}
})
</script> </html>

谢谢观看!!!
Vue模板语法(一)的更多相关文章
- Vue模板语法(二)
Vue模板语法(二) 样式绑定 class绑定 使用方式:v-bind:class="expression" expression的类型:字符串.数组.对象 1.2 style绑 ...
- Vue模板语法(一)
Vue模板语法 一.插值 1.1.1 文本 {{msg}} 1.1.2 html 使用v-html指令用于输出html代码 1.1.3 属性 HTML属性中的值应使用v-bind指令 1.1.4 表达 ...
- Vue 模板语法 && 数据绑定
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8" /> 5 & ...
- 初始Vue、Vue模板语法、数据绑定(2022/7/3)
文章目录 1.Vue简介 1.1.Vue的安装使用 1.2.实际的运用案例 1.3.vue开发工具的使用(这个需要在浏览器中安装) 2.初始Vue 2.1 .基础知识 2.1 .代码实例 2.2 .页 ...
- (Vue)vue模板语法
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.Vue.js 的核心是一个允许你采用简洁的模板语法来声明式的将数据渲染进 DOM 的系统. ...
- Vue模板语法与常用指令
Vue.js 使用了基于 HTML 的模板语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.在底层的实现上,Vue 将模板编译成虚拟 DOM 渲染函数,结合相应系统,在应用状态改变时 ...
- Vue模板语法(二)
Vue基础模板语法 二 1. 样式绑定 1.1 class绑定 使用方式:v-bind:class="expression" expression的类型:字符 ...
- (32)Vue模板语法
模板语法 文本: <span>Message: {{ msg }}</span> v-once 一次性地插值,当数据改变时,插值处的内容不会更新 <span v-once ...
- 11 - Vue模板语法
Vue.js 使用了基于 HTML 的模板语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. 所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML ...
随机推荐
- c++修改打印机名称
public static bool SetPrinterName(string OldName, string newName) { IntPtr hPrinter; PrintAPI.struct ...
- Python-11-生成器
一.定义 可以理解为一种数据类型,这种数据类型自动实现了迭代器协议(其他数据类型需要调用__iter__方法),所以生成器就是一种迭代器. 二.生成器的两种形式 1. 生成器函数 使用yield代替r ...
- 33 Eclipse无法查看源码解决
问题如图 点击 Attach Source 解决方法 下载src.zip包,src包地址:https://pan.baidu.com/s/1oAqqqHO 选择此src包即可
- pandas再次学习
numpy.scipy官方文档 pandas官方网站 matplotlib官方文档 一.数据结构 二.数据处理 1.数据获取(excel文件数据基本信息) #coding=utf-8 import ...
- swagger 报错:illegal defaultValue null for param type integer
swagger(版本2.9.2) 刷新报错,错误信息如下图: 问题原因: 根据上面这句报错信息,点进去AbstractSerializableParameter.java:412可以看到 源码, @J ...
- cookie遇到java.lang.IllegalArgumentException: Control character in cookie value or attribute
java.lang.IllegalArgumentException: Control character in cookie value or attribute. 该异常说明cookie中的val ...
- DML 操作表中数据
DML 是对于表中的记录进行增删改操作 一.添加数据 语法格式: insert into 表名[字段名] values[字段值] 表名:表示往那张表中添加数据 (字段名1,字段名2, ...
- JAVA - Windows下JDK默认安装的配置参数
JDK版本1.8 JAVA_HOME C:\Program Files\Java\jdk1.8.0_60 CLASSPATH .;%%JAVA_HOME%%\lib;%%JAVA_HOME%%\lib ...
- ERROR: Cannot uninstall 'chardet'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
pip 安装 docker库报错: ERROR: Cannot uninstall 'chardet'. It is a distutils installed project and thus we ...
- SIM900 HTTP POST
AT+SAPBR=3,1,"CONTYPE","GPRS" OK AT+SAPBR=3,1,"APN","CMNET" ...