Vue局部混入

 

一 需要混入的配置

 

export const options = {
    beforeCreate() {
        console.log('混入的beforeCreate钩子');
    },
    methods: {
        print() {
            console.log('混入的print方法');
        }
    }
};

 

二 组件

 

<template>
	<div class="app">App组件</div>
</template>

<script>
import { options } from "./mixin.js";

export default {
  name: "App",
  mixins:[options],
  data() {
    return {};
  }
};
</script>

<style lang="scss" scoped>
.app{
    background:gray;
}
</style>

 

三 结果

 

本组件中也会含有混入的配置。

 

 


版权声明:本文为weixin_45895753原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。