vue3的hooks与vue2的mixins用法对比

vue2的mixins写法

这是一个混入js
demoMixins.js

export default {
  data() {
    return {
      dataList: {
        initData: {
          price: 122,
          title: '当当图书系统',
          type: '考研辅导',
          url:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgx.wadongxi.net%2Fitem%2Fi1%2FTB10n5oKFXXXXbXXXXXXXXXXXXX_%21%210-item_pic.jpg_400x400Q90.jpg&refer=http%3A%2F%2Fimgx.wadongxi.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1636647015&t=1d73de8682aa7f14e87c377139b560b1',
        },
        dataArr: [],
      },
    };
  },
  //处理列表数据
  mounted() {
    for (let i = 0; i < 50; i++) {
      this.dataList.dataArr.push(this.dataList.initData);
    }
  },
};

demo.vue组件需要demoMixins.js的方法,处理如下





你可能感兴趣的:(vue2/vue3全家桶,javascript,vue.js)