vue-mixin用法

创建一个mixin的方法 test.js

export default {
    data: function () {
        return {
            pagination: {
                items: [],
                total: 0,
                per_page: 10,
                from: 1,
                to: 0,
                current_page: 1,
            },
            search: {},
        }
    },
    mounted() {
        this.fetchItems();
    },
    updated() {
        
    },
    methods: {
        handleSizeChange(val) {
            this.pagination.per_page = val;
            this.fetchItems();
        },
        handleCurrentChange(val) {
            this.pagination.current_page = val;
            this.fetchItems();
        },
        fetchItems() {
            console.log(this.pagination.current_page)
            console.log("fetch-items")
        },
    }
};

在content.vue组件里面应用

import listMixin from './test';
export default {
    components: {
        
    },
    mixins: [listMixin],

 

posted @ 2020-11-23 20:14  许伟强  阅读(111)  评论(0编辑  收藏  举报