创建 mixin文件  mixins.js


const baseMixin = {
	data() {},
	methods: {
		btnClick() {
			console.log('点击事件触发');
		},
	},
};

export default baseMixin;

 在入口文件 main.js 中引入

import mixin from "./mixins/index.js";

app.mixin(mixin)
	

页面中使用

<template>
    <div>

    </div>
</template>

<script>
   import { onMounted,onUnmounted, getCurrentInstance, ref,reactive,toRefs } from 'vue';
   import { useStore } from 'vuex';
   import { useRouter } from 'vue-router';
   export default {
       components: {
       },
       setup() {
           let store = useStore();
           let route = useRouter();
           let state = reactive({
                                 
           })
           const { proxy } = getCurrentInstance();
           onMounted(()=>{
                proxy.btnClick()
           })
           onUnmounted(()=>{
           
           })
           return {
               ...toRefs(state)
           }
       }
   };
</script>

<style scoped lang="less">

</style>

Logo

前往低代码交流专区

更多推荐