シリーズ記事ディレクトリ
Vue3作成プロジェクト第2弾(2)ルータのルーティング設定と使い方
目次
Main.js の構成は、次のように図を直接確認してください。
//main.js 設定の順番は以下の通りです、ごちゃごちゃしません!!!!問題がある場合は、エラーを報告するのが簡単です
Main.js の構成は、次のように図を直接確認してください。
序文:
初心者が vue3 プロジェクトを作成するとき、多くの構成を使用し、順序が間違っているか、コンポーネントの導入が間違っていて、依存関係が間違っていて、構成が間違っているなど、多くの間違いを犯すことになります。この記事では主に次の点について説明します。の設定とインストール方法、およびピット回避ガイドについて、私が踏んだピットは後で回避でき、先代は木陰におり、子孫は木陰を楽しんでいます。
//main.js 設定の順番は以下の通りです、ごちゃごちゃしません!!!!問題がある場合は、エラーを報告するのが簡単です
//main.js 配置 顺序依次如下,不能乱!!!!乱了容易报错
/***
*
* router 路由
*
* store vuex全局管理
*
* elementplus
*
*/
import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store/index'
//引入elementplus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//引入elementplus icon
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
// 使用use将文件挂载上去
createApp(App).use(router).use(store).use(ElementPlus).mount('#app')
以下にいくつかのインストールコマンドを示します
エレメントプラスコマンドのインストール
npm install element-plus --save
要素 の構成- アイコン
npm install @element-plus/icons-vue
//main.js中配置
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(router).use(ElementPlus).mount('#app')
ルーターをインストールする
npm install vue-router@4
vuexをインストールする
npm install vuex@next --save
やっと:
他の構成は後で補足および更新されます
役に立ち、興味があると思われた場合は、注目してください。後で提案がある場合は、直接メッセージを残してください。