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']
}
相關文章
相關標籤/搜索