亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

VueJS不使用“/”路線打開主頁

VueJS不使用“/”路線打開主頁

九州編程 2021-09-04 17:53:50
我想顯示一個帶有h1文本的簡單主頁,但它不起作用。我配置了路由并將其添加到main.js. 當我瀏覽到localhost:8080什么都沒有顯示時。我看不出它不起作用的原因。主文件import Vue from 'vue'import App from './App'import router from './router'Vue.config.productionTip = falsenew Vue({  el: '#app',  router,  components: { App },  template: '<App/>'})應用程序<template>  <div>    <router-view/>  </div></template><script>export default {  name: 'App'}</script>主頁.vue<template>    <div>        <h1>Home</h1>    </div></template><script>    export default {        name: 'home'    }</script>/路由器/index.jsimport Vue from 'vue'import Router from 'vue-router'import Home from '@/components/Home'Vue.use(Router)export default new Router({    mode: 'history',    routes: [        {            path: '/',            name: 'Home',            component: Home        }    ]})索引.html<!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width,initial-scale=1.0">    <link rel="icon" href="<%= BASE_URL %>favicon.ico">    <title>client</title>  </head>  <body>    <noscript>      <strong>We're sorry but client doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>    </noscript>    <div id="app"></div>    <!-- built files will be auto injected -->  </body></html>
查看完整描述

1 回答

?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

@vue/cli默認情況下僅使用 vue 運行時,而不使用vue 編譯器(如果要使用內聯模板字符串,則需要編譯器)


要解決此問題,您可以在以下文件中打開 runtimeCompilervue.config.js:


module.exports = {

  "runtimeCompiler": true

};

或者更改您的代碼以使用該render()函數:


new Vue({

  el: '#app',

  router,

  components: { App },

  template: '<App/>'

})


new Vue({

  router,

  render: h => h(App)

}).$mount("#app")

順便說一句,如果您正在使用@vue/cli,則可以選擇Manually select featuresduring vue create。

當您選擇Router一個功能時,您將獲得一個啟動的項目,vue-router該項目將開箱即用。


查看完整回答
反對 回復 2021-09-04
  • 1 回答
  • 0 關注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號