How to use mixin within uni.APP

1. First of all, create a folder in the root directory of the project to be internally deconstructed into index.js and mixin.js

2. In the new mix folder content so

The index of js

import initMixin from "./mixin"
export default {
	install(Vue) {
		initMixin(Vue)
	}
}
Copy the code

Mixins. Js

In addition, it is recommended to enclose your own method names with a $in front of them to distinguish between framework methods and native methods

export default Vue => {
	Vue.mixin({
		methods:{
			$go(url,isTab){
				// Check whether it is a TAB page
				if(isTab){
					uni.switchTab({
						url
					})
				}else{
					uni.navigateTo({
						url
					})
				}
				
			}
		}
	})
}

Copy the code

3. After that, calls to vue main.js can be mixed in and imported from wherever they are placed

import Vue from 'vue'
import App from './App'


Vue.config.productionTip = false
import initMixin from './core'
Vue.use(initMixin)
App.mpType = 'app'

const app = newVue({ ... App }) app.$mount()Copy the code

4. Then call the this.XX method directly in the project