[TOC]
#### Vue 國際化
* [ ] 文檔 https://github.com/kazupon/vue-i18n
* [ ] 安裝 cnpm i -S vue-i18n
* [ ] 使用
1. src 目錄下新建 lang 文件夾

*****
2. cn.js en.js
~~~
const messages = {
home: {
title:
'書城',
hint: '計算機科學和軟件工程',
guessYouLike: '猜你喜歡',
change: '換一批',
clear: '清空',
hotSearch: '熱門搜索',
historySearch: '搜索歷史',
sameAuthor: '與$1同作者',
sameReader: '對$1感興趣的人也在讀',
readPercent: '閱讀$2的人,$1都在讀',
recommend: '熱門推薦',
seeAll: '查看全部',
readers: '$1人同時在讀',
featured: '精選',
category: '分類',
books: '本書',
readNow: '立即閱讀',
allBook: '共 $1 本圖書'
}
}
export default messages
~~~
~~~
const messages = {
home: {
title:'Book Store',
hint: 'Computer Science And Software Engineering',
guessYouLike: 'Guess You Like',
change: 'Change',
clear: 'Clear',
hotSearch: 'Hot Search',
historySearch: 'History Search',
sameAuthor: 'Same author with $1',
sameReader: 'Same reader with $1',
readPercent: '$1 is reading $2',
recommend: 'Recommend',
seeAll: 'See all',
readers: '$1 is reading',
featured: 'Featured',
category: 'Category',
books: 'books',
readNow: 'Read Now',
allBook: '$1 books'
}
}
export default messages
~~~
*****
3. index.js
~~~
import Vue from 'vue'
import VueI18N from 'vue-i18n'
// 引入中英文
import en from './en'
import cn from './cn'
import { getLanguage, saveLanguage } from '@/utils/storages'
// 插件注冊
Vue.use(VueI18N)
const messages = {
en,
cn
}
// 從緩存中獲取
let locale= getLanguage()
// 不存在 則 設置一個默認語言,然后保存在緩存中
if (!locale) {
locale= 'cn'
saveLanguage( locale)
}
// i18n 配置
const i18n = new VueI18N({
locale, // 語言
messages // 語言包
})
export default i18n
~~~
*****
~~~
import Storage from 'web-storage-cache'
const localStorage = new Storage()
export function setLocalStorage(key, value)
{
return localStorage.set(key, value)
}
export function getLocalStorage(key)
{
return localStorage.get(key)
}
export function removeLocalStorage(key)
{
return localStorage.delete(key)
}
export function clearLocalStorage()
{
return localStorage.clear()
}
// 獲取語言
export function getLanguage()
{
return getLocalStorage('locale')
}
// 設置語言
export function saveLanguage(value)
{
return setLocalStorage('locale', value)
}
~~~
*****
4. man.js 引入 國際化

~~~
import 'babel-polyfill'
import Vue from 'vue'
import './cube-ui'
import App from './App.vue'
import router from './router'
import store from './store'
import i18n from './lang'
import 'amfe-flexible'
import fastClick from 'fastclick'
import 'assets/stylus/base.styl'
fastClick.attach(document.body)
Vue.config.productionTip = false
new Vue({
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')
~~~
*****
5. 組件中使用

~~~
<div class="title">
<div class="title-down" @click="hidePopUp"><i class="icon-down2"></i></div>
{{$t('book.selectFont')}}
</div>
~~~
- 起步
- 環境搭建
- mock數據
- 基礎
- 生命周期
- 過濾器
- 過渡動畫
- keyframes動畫
- 動畫JS鉤子
- 路由
- 導航守衛
- 全局守衛
- 監聽器
- 自定義組件
- 獲取焦點
- mixins
- mixins抽離vuex
- 國際化
- 動態組件
- Dom
- 擴展
- 安裝devTools
- scss
- Nuxt引用多個UI庫
- vuex
- vuex命名空間
- vuex定義
- cli
- 安裝與卸載
- 環境變量
- 雜項
- Mock數據
- FeHelper
- git
- 反向代理
- 本地存儲
- stylus
- 常用mixins
- jsonp
- 配置
- mock配置
- 跨域配置
- 自定義路徑
- px2rem
- 代理后端請求
- 常用算法
- 字母排序城市數據
- 倒計時
- 通訊錄數據結構
- 請求
- axios防止多次請求
- 封裝axios請求
- axios使用
- 封裝axios
- 插件
- BetterScroll
- 高德定位
- polyfill
- fastClick
- LazyLoad
- storageCache
- moment
- keyFrameAnimation
- vueSwiper
- 組件
- Loading組件
- header組件
- 仿有道App導航
- SupportIcon
- 仿餓了么購物車跳動
- 購物車小球緩動
- 小球飛入購物車
- 仿音樂歌手列表
- 唱片飛入效果
- 搜索組件
- 仿美團PC搜索框
- 頁面布局
- stickyFooter
- 背景色漸變
- 背景虛化
- Ui組件
- CubeUi
- CreateApi
- tab滑屏切換
- 索引列表
- BScroll
- BScroll左右聯動導航
- vant
- 函數庫
- 常用Dom函數庫
- axios封裝
- 格式化音樂播放時長
- 搜索節流
- time格式化
- JS基礎
- window對象中的高度
- JS中的寬高
- 常用正則
- nuxt
- nuxtVuex
- 監聽頁面滾動
- 監聽body滾動
- 監聽局部滾動