相关疑难解决方法(0)

"export 'default' (imported as 'Vue') was not found in 'vue'

I am a beginner with VueJs and this is my first App:

import { BootstrapVue } from 'bootstrap-vue'
import { createApp } from 'vue'
import App from './App.vue'
    
const myApp = createApp(App)
myApp.use(BootstrapVue)
myApp.mount('#app')
Run Code Online (Sandbox Code Playgroud)

And when I save, nothing appears in my browser and it show this message in the Command:

warning  in ./src/main.js

"export 'default' (imported as 'Vue') was not found in 'vue'
Run Code Online (Sandbox Code Playgroud)

vue.js

25
推荐指数
4
解决办法
6万
查看次数

如何在Vue 3中的Vue Router中获取cookie?这在 router/index.js 中未定义

使用案例:使用express作为API后端的Vue3应用程序。Express 使用express-sessions 建立服务器端会话,该会话发送到浏览器并在每个后续请求中接收。

我正在尝试创建一个路由防护,以防止在会话 cookie 不存在时访问某些路由。

"vue": "^3.0.11",
"vue3-cookies": "1.0.1",
Run Code Online (Sandbox Code Playgroud)

我已经安装了以下 NPM 包

https://www.npmjs.com/package/vue3-cookies

然后在main.js

import VueCookies from 'vue3-cookies'
app.use(VueCookies);
Run Code Online (Sandbox Code Playgroud)

然后在router/index.js

function requireAuth(to,from,next){
  console.log(this);
  console.log(this.$cookies.get('_ga'))
  next();
}

const routes = [
  {
    path: '/',
    name: 'ProtectedRoute',
    component: ProtectedRoute,
    beforeEnter:requireAuth
  }

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

Error: [Vue Router warn]: Unexpected error when starting the router: TypeError: Cannot read property '$cookies' of undefined
Run Code Online (Sandbox Code Playgroud)

我试过了

this.$cookies.get('_ga')
Vue.$cookies.get('_ga')
window.$cookies.get('_ga')
Run Code Online (Sandbox Code Playgroud)

没有工作。

我也尝试过将 Vue 导入到 index.js 文件中,但失败了,可能是因为在 Vue3 中你无法将 Vue …

javascript session-cookies vue.js vuejs3

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

vue.js ×2

javascript ×1

session-cookies ×1

vuejs3 ×1