国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

VUE項(xiàng)目依賴包安裝及配置

這篇具有很好參考價(jià)值的文章主要介紹了VUE項(xiàng)目依賴包安裝及配置。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1.安裝axios ,router,vue-router,vuex? (npm i xxx -S)

注意依賴包對(duì)應(yīng)版本

VUE項(xiàng)目依賴包安裝及配置

?2. elementui 按需引入配置

npm i element-ui -S

npm install babel-plugin-component -D

babel.config.js文件添加配置

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],// 這個(gè)不修改
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

VUE項(xiàng)目依賴包安裝及配置

main.js

import {Button, Select} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(Button)
Vue.use(Select)

不要把組件注冊(cè)寫成對(duì)象格式:Vue.use({Button,Select}),無(wú)法正常注冊(cè)

VUE項(xiàng)目依賴包安裝及配置

?3. router設(shè)置

在src下新建router目錄,創(chuàng)建index.js,文件內(nèi)容如下

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

export default new VueRouter({
    routes:[
        {
            name:'歡迎頁(yè)',
            path:'/hello',
            component:()=>import('@/components/HelloWorld')
        }
    ]
})

在main.js注冊(cè)路由

VUE項(xiàng)目依賴包安裝及配置

?使用路由

VUE項(xiàng)目依賴包安裝及配置

4.vuex設(shè)置

在src下新建store目錄,創(chuàng)建index.js,文件內(nèi)容如下

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store(  {
    namespaced:true,//開(kāi)啟命名空間,避免沖突
    // 提供唯一的公共資源,所以共享的數(shù)據(jù)統(tǒng)一放到store進(jìn)行儲(chǔ)存,類似data
    state:{
        testID:'123456'
    },
    getters:{},
    mutations:{},
    actions:{},
    modules:{}
})

在main.js入口文件中注冊(cè)store

VUE項(xiàng)目依賴包安裝及配置

?在組件里使用testID,出現(xiàn)報(bào)錯(cuò)"$store" is not defined on the instance but referenced during render...

VUE項(xiàng)目依賴包安裝及配置

VUE項(xiàng)目依賴包安裝及配置

?查看package.json發(fā)現(xiàn)vuex版本不匹配

VUE項(xiàng)目依賴包安裝及配置

vuex現(xiàn)在默認(rèn)vuex4版本,vuex4只能在vue3中使用,在vue2中能使用vuex3,當(dāng)前項(xiàng)目使用vue2

刪除node_modules目錄下的vuex文件夾及package.json的vuex,重新安裝vuex@3

?npm install vuex@3 -S

VUE項(xiàng)目依賴包安裝及配置

5.axios配置

import Axios from "axios";

const instance = Axios.create({
  baseUrl: "/api",
});

instance.interceptors.request.use(
  (config) => {
    // console.log(config);
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

instance.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default instance;

VUE項(xiàng)目依賴包安裝及配置

?

6.項(xiàng)目上傳到git倉(cāng)庫(kù)

VUE項(xiàng)目依賴包安裝及配置

VUE項(xiàng)目依賴包安裝及配置

VUE項(xiàng)目依賴包安裝及配置

這樣就是成功了?

VUE項(xiàng)目依賴包安裝及配置文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-428515.html

到了這里,關(guān)于VUE項(xiàng)目依賴包安裝及配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包