2017-07-25 44 views

回答

2

使用函数来构建组件。

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。

相关问题