npm i [email protected]
注意:这里下载的是7.3.3版本,如果没有指定版本vue2好像不能使用。
这是出现的报错。
// 引入vue-i18n包
import VueI18n from "vue-i18n";
import Vue from "vue";
// 应用vuei18n
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: "zh",
// 配置语言文件对象
messages: {
en: {
home: "home",
},
zh: {
home: "首页",
},
},
});
export default i18n;
import i18n from '../lang/index'
new Vue({
i18n,
render: h => h(App),
}).$mount('#app')
这样我们就可以在vue的实例上使用我们挂载的方法对象了。
{{ $t("home") }}
通过这一番操作我们间接的看下vuex和vue-router是如何进行配置的。
这是通过自定义配置的项目文件
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
配置基地址
路由的模式
对于文件的路径
export default router
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
},
getters: {
},
mutations: {
},
actions: {
},
modules: {
}
})
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')