34 lines
952 B
JavaScript
34 lines
952 B
JavaScript
import App from './App'
|
|
import ajax from '@/common/ajax.js' // 路径需根据项目实际情况
|
|
import store from './store'
|
|
// #ifndef VUE3
|
|
import Vue from 'vue'
|
|
Vue.config.productionTip = false
|
|
// Vue2:挂载在 Vue 原型链上,则通过 this.$ajax 调用
|
|
Vue.prototype.$ajax = ajax
|
|
App.mpType = 'app'
|
|
const app = new Vue({
|
|
...App
|
|
})
|
|
app.$mount()
|
|
// #endif
|
|
|
|
// #ifdef VUE3
|
|
import {
|
|
createSSRApp
|
|
} from 'vue'
|
|
export function createApp() {
|
|
const app = createSSRApp(App)
|
|
app.use(store)
|
|
// Vue3 (Options API):挂载在当前应用上(app 为 createSSRApp 后的应用),也是通过 this.$ajax 调用
|
|
// 我们在写 Vue3 时更推荐用 Composition API,即不挂载在实例上
|
|
app.config.globalProperties.$ajax = ajax
|
|
// 如果你在项目中有用到 nvue 页面,是无法通过 this.$ajax 调用
|
|
// 需要将请求方法添加到 uni 对象上,然后通过 uni.$ajax 调用
|
|
uni.$ajax = ajax
|
|
return {
|
|
app
|
|
}
|
|
}
|
|
// #endif
|