creates the filters folder, which creates a filters.js file to define the global filter
image.png

filters.js

let filterOne = (value) => {
  return value * 10
}
let filterTwo = (value, pm) => {
  return value * pm
}
export default {
  filterOne,
  filterTwo
}

main.js

import filters from './filters/filters.js'
for (let value in filters) {
  // value是filter名称(字符串)
  // filters[value] 对象里面的某个元素,就是filters中定义的方法
  Vue.filter(value, filters[value])
}

thus defines all filters globally and can be used in the interface.

年龄:{{ age | filterOne | filterTwo(0.5) }}

张旭超
1.4k 声望222 粉丝

精通 html+div+css jquery, vue, angularjs, angular2, angular4, ionic, ionic2