参考网址:https://segmentfault.com/a/1190000010507616
下面栗子中,
callback是传递父组件的方法,
mutationName是传递父组件的数据,
App.vue
<search-bar class="f-fr" placeholder="请输入名字" mutationName='resetListData' :callback="callback"/>
SearchBar.vue
export default {
name: 'SearchBar',
data() {
return {
input: ''
}
},
methods: {
setName: function () {
var input = this.input;
if (input.trim() == '') {
alert("empty");
}
else {
Api.searchTest(this.input,this.success );
}
},
success(responseData) {
this.callback(responseData);
},
},
props: ['placeholder', 'apiName', 'moduleName', 'mutationName','callback']
}