Javascript 在Vuejs中,如何将watcher添加到所有道具中,并使用与回调相同的函数?
作为标题,我想为所有道具添加watcher和相同的回调,但我需要在子组件中编写如下代码:Javascript 在Vuejs中,如何将watcher添加到所有道具中,并使用与回调相同的函数?,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,作为标题,我想为所有道具添加watcher和相同的回调,但我需要在子组件中编写如下代码: 导出默认值{ 道具:{ a:弦, b:绳子, c:字符串 }, 观察:{ a(v){this.handler(v)}, b(v){this.handler(v)}, c(v){this.handler(v)}, }, 方法:{ 处理程序(v){ //代码。。。 } } } 使用函数构建组件 function buildComponent(properties){ const base = { met
导出默认值{
道具:{
a:弦,
b:绳子,
c:字符串
},
观察:{
a(v){this.handler(v)},
b(v){this.handler(v)},
c(v){this.handler(v)},
},
方法:{
处理程序(v){
//代码。。。
}
}
}
使用函数构建组件
function buildComponent(properties){
const base = { methods:{ handler(v){ console.log(v) }}, props:{}, watch:{}}
for (let prop of properties){
base.props[prop] = String
base.watch[prop] = function(v) {this.handler(v)}
}
return base
}
export default buildComponent(["a","b","c"])
Vue只是javascript