nuxt項目踩坑

一、window or document is not undefinedjavascript

 

// .vue 頁面
if (process.browser) {
  var Distpicker = require('v-distpicker')
  Vue.use(Distpicker)
  Vue.component('v-distpicker', Distpicker)
}

// nuxt.config.js
build: {
    vendor: ['v-distpicker']
}  

這樣會報錯:[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.vue

修改.vue頁面引入java

<no-ssr><v-distpicker :placeholders="form.placeholders"></v-distpicker></no-ssr>

二、vee-validate本地化node

按照官網的本地化各類報錯:另外須要注意的是部分文件/配置修改須要重啓服務nginx

//頁面內
const dictionary = {
  zh_CN: {
    custom:{
      lender:{
        type:{
          required: () => '類型不能爲空'
        }
      }
    },
    messages: {
      lender: {
        code: () => 'ssss',
      }
    },
    attributes: {
      lender: {
        code: '資方編碼'
      }
    }
  }
};

Validator.localize(dictionary);

//vue
<p>
	<input v-validate="'required|sss'" name="sss" type="text" placeholder="sss">
	<span v-show="errors.has('sss')">{{ errors.first('sss') }}</span>
</p>

//公用
Validator.extend('sss', {
  getMessage: field =>  field + '必須是一個手機號.',
  validate: value =>  {return value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)}
});

//按鈕觸發
onSubmit() {
      this.$validator.validateAll().then((result) => {
        if (result) {
          console.log('ok?')
          return;
        }
        console.log('咋啦');
      });
}   



// /plugs/vee-validate.js本地化配置

import Vue from 'vue' import VeeValidate,{Validator} from 'vee-validate'; import zh_CN from 'vee-validate/dist/locale/zh_CN'; import VueI18n from 'vue-i18n'; Vue.use(VueI18n); const i18n = new VueI18n({ locale: 'zh_CN' }); Vue.use(VeeValidate, { i18n, fieldsBagName: 'field', dictionary: { zh_CN: { messages: { email: () => '請輸入正確的郵箱格式,哼哼哼哼哼', required: (field) => "請輸入" + field }, attributes: { // email:'郵箱有毒嗎', password: '密碼', name: '帳號', phone: '手機', lender: { code: '資方編碼' } } } } });

##### 常規上線步驟
* npm run build編譯後將文件傳至服務器ssh root@111.11.11.111
* 服務器目錄爲/home/nuxt (須要上傳的未見爲package.json和.nuxt文件)
* 安裝好node(推薦nvm)和 yarn,npm i --production 或者yarn i --production 安裝好後運行npm run start啓動服務
* 須要配置好nginx(ubuntu下的配置爲:/etc/nginx/nginx.conf查看內容能夠看到底部引入
include/etc/nginx/conf.d/*.conf;
include/etc/nginx/sites-enabled/*;
進入sites-enabled目錄下配置nginx的sercer代理便可
)

git

## 使用docker快速開始
- 首先,須要訪問[docker官網](https://www.docker.com/)根據不一樣操做系統獲取docker
- docker官方文檔:https://docs.docker.com/
- mongo dockerhub文檔:https://hub.docker.com/_/mongo/ (關於auth/volumes一些問題)github

``` bash
# development mode(use volumes for test-edit-reload cycle)
# 開發模式(使用掛載同步容器和用戶主機上的文件以便於開發)
# Build or rebuild services
docker-compose build
# Create and start containers
docker-compose updocker

# production mode
# 生產模式
# Build or rebuild services
docker-compose -f docker-compose.prod.yml build
# Create and start containers
docker-compose -f docker-compose.prod.yml up數據庫

# 進入容器開啓交互式終端
# (xxx指代容器名或者容器ID,可由`docker ps`查看)
docker exec -it xxx bash
```npm

> 注:爲了防止生產環境數據庫被改寫,生產模式數據庫與開發環境數據庫的連接不一樣,開發環境使用vue-blog,生產環境使用vue-blog-prod,具體能夠看docker-compose配置文件


https://github.com/BUPT-HJM/vue-blog

  

vue 遍歷賦值屬性節點(轉義),這點卡了好久

:name="`form.contactsList${scope.row.index}.date`"

相關文章
相關標籤/搜索