watch,computed,src
2019-10-26 本文已影响0人
吃冬瓜的小学生
Watch
kmh_2019_06:{
handler(newName, oldName) {
//this.popupCard()
popupCard()
},
immediately:true, //刚绑定上数据就来一发handler操作,默认false
deep: true //深度监听 eg:kmh_2019_06{'zc':{'zcNo':'xxxx','zcName':'xx'}}
}
computed
//html
<div>{{kmh_2019_01_1_com(1)}}</div>
//js
kmh_2019_01_1_com:function(){
let that = this
//如果computed需要传参数,就让这个计算属性返回个函数,在再html中绑定这个函数
return function(returnType){
let sumCnt = 0
let sumPrem = 0
}
}
src
- static文件夹中的不会编译
<div v-for="item in images">
<img :src="item.src" />
</div>
import imgJson from '../static/img.json' //不知为何改成绝对路径/static就报错
data(){
return {
images:imgJson.imgArr
}
}
//
var imgJson = {
imgArr:[
{
src:'static/img/aa.png'
},
{
src:'static/img/aa.png'
}
]
}
- assets中的会被编译,所以引用要加require
<template>
<div>
<img :src="imgUrl[0].src"/>
</div>
<template>
//js部分
data(){
return {
imgUrl:[{src:require(‘./1.png’)},{src:require(‘./1.png’)}]
}
}