其他分享
首页 > 其他分享> > filters获取data中的数据

filters获取data中的数据

作者:互联网

第一种:改变this指向

beforecreate(){
    that = this;
},
data(){
  return{
    option:[]
  }
},
filters:{
  formatDAata(value){
    let value;
    that.option.map((item,index)=>{
        console.log(item);
        value = item;
    })
     return value;
  }
}

 第二种:给filter传递参数

<div>
  <el-table-column label="类型">
    //此处的list是data中的数据
    <template slot-scope="scope">{{ scope.row.type|formatType(list)}}</template>
  </el-table-column>
</div>

data(){
  return{
      list:[]
  }
},
filters:{
  /**
     * 格式化主题类型
     * @param {*} value 格式化数字
     * @param {*} options 查询所有主题数组
     */
    formatType(value, options) {
        let typeName;
        options.map(res => {
            if (value == res.type) {
                typeName = res.name;
            }
        });
        return typeName;
    }
 }

标签:return,typeName,res,value,获取,filters,data
来源: https://blog.csdn.net/zhao_li_ming/article/details/120829028