尝试导入Vue到Vue路由器



我可以在vue路由器文件中写入'import {vue} from 'vue'吗

import home from '../components/home.vue'
import  {vue} from 'vue'
import VueMeta from 'vue-meta'
vue.use(VueMeta , {
keyName: 'metaInfo',
attribute: 'data-vue-meta',
ssrAttribute: 'data-vue-meta-server-rendered',
tagIDKeyName: 'vmid',
refreshOnceOnNavigation: true
})
const router = createRouter({
history: createWebHistory(),
routes: 
{
path: '/',
name: 'home',
component: home
},
{
path: '/business',
name: 'business',
component: () => import('../components/business.vue')
},
{
path: '/about',
name: 'about',
component: () => import('../components/about.vue')
},
{
path: '/faqs',
name: 'faq',
component: () => import('../components/faq.vue')
},
{
path: '/termOfServices',
name: 'termOfServices',
component: () => import('../components/termOfServices.vue')
}
],
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return {
el: to.hash,
behavior: 'smooth'
}
}
if (savedPosition) {
return savedPosition
} else {
return {top: 0}
}


}
})
export default router

只是想知道,因为当我运行这个我得到错误'Uncaught SyntaxError:请求的模块'/node_modules/.vite/deps/vue.js?V =5d26be8a'没有提供名为'default "的导出我想使用vue-meta库进行网站的seo从文档中,我必须在路由器页面中导入vue,然后才能使用vue-meta

试试这个方法:

import Vue from 'vue'
import VueMeta from 'vue-meta'
Vue.use(VueMeta, {
keyName: 'metaInfo',
attribute: 'data-vue-meta',
ssrAttribute: 'data-vue-meta-server-rendered',
tagIDKeyName: 'vmid',
refreshOnceOnNavigation: true
})

对于最新版本的Vue3,尝试使用:

import { createApp } from 'vue'
import App from './App.vue'
import VueMeta from 'vue-meta'
const app = createApp(App)
app.use(VueMeta, {
keyName: 'metaInfo',
attribute: 'data-vue-meta',
ssrAttribute: 'data-vue-meta-server-rendered',
tagIDKeyName: 'vmid',
refreshOnceOnNavigation: true
}))

相关内容

  • 没有找到相关文章

最新更新