Vue.js学习笔记(6)关于资源使用
2018-08-25 本文已影响15人
程序员不务正业
- 获取本地图片两种方式
- assets、static中使用资源方式
1、img: require('../assets/100x100.png')
2、img: 'static/100x100.png'
tabList: [
{
id: '事业',
img: 'static/100x100.png'
// img: require('../assets/100x100.png')
},
{
id: '资讯',
img: 'static/100x100.png'
},
{
id: '工具',
img: 'static/100x100.png'
},
{
id: '我的',
img: 'static/100x100.png'
}
]
- 双向数据绑定与监听
<div>
<input placeholder="输入测试数据" v-model="text">
{{text}}
<button @click="chanågeMessage">修改文字</button>
</div>
watch: {
text: function(newV, oldV) {
console.log(newV);
}
},
data() {
return {
text: "内容"
};
}
- 数据整体监听与计算
computed
<div>
单价:<input type="text" name='' v-model="price"> *
件数:<input type="text" name='' v-model="num"> *
折扣:<input type="text" name='' v-model="rate"> = {{sum}} (元)
</div>
// 计算属性
computed: {
sum(){
return this.price *this.num * this.rate
}