uni-app vue3报错’default’ is not exported by node_modules/@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js, imported

uni-app创建的vue3项目,报错信息:

15:26:20.634   1: import Vue from 'vue';
15:26:20.637             ^
15:26:20.646   2: 
15:26:20.648   3: const check_text = (content, cb) => {
15:32:39.668 'default' is not exported by node_modules/@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js, imported by ../utils/security.js

问题很明显是导入有问题,下面这语法是vue2的:

import Vue from 'vue';

vue3中是没有Vue全局变量的,从uni-app默认模板main.js中能清楚看出用法区别:

import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

vue3导入方式为:

import { createSSRApp } from 'vue'

当然,也可以全部导出:

import * as Vue from 'vue'

vue2和vue3不兼容,特别坑。。。慢慢踩吧

(版权归cpury.com所有,转载请注明出处。)