vue 父组件通过props向子组件传递数据/方法的方式

参考网址: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']
}

猜你喜欢

转载自www.cnblogs.com/zhaomeizi/p/9183820.html