[英]Vue2 / vue-router / Laravel - router-view not showing a Vue Component
我遇到了一個問題,我的 Vue 組件沒有通過路由器視圖顯示,控制台中沒有 Vue 警告或錯誤。
這是 git: https://github.com/woottonn/fullstack
這是我的代碼:
Welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Full Stack Blog</title>
</head>
<body class="antialiased">
<div id="app">
<mainapp></mainapp>
</div>
<script src="{{mix('/js/app.js')}}"></script>
</body>
</html>
應用程序.js
require('./bootstrap');
import Vue from 'vue'
import router from './router'
Vue.component('mainapp', require('./components/mainapp.vue').default)
const app = new Vue({
el: '#app',
router
});
路由器.js
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import myFirstVuePage from './components/pages/myFirstVuePage'
const routes = [
{
path: '/my-new-vue-route',
component: myFirstVuePage
}
];
export default new Router({
mode: 'history',
routes
})
主應用程序.vue
<template>
<div>
<h1>VUE Componenty</h1>
<router-view></router-view>
</div>
</template>
myFirstVuePage.vue
<template>
<div>
<h1>This is my first page...</h1>
</div>
</template>
我在這里遺漏了明顯的東西嗎?
--- 編輯:直接轉到 URL (/my-new-vue-route) 會引發錯誤,所以這也不起作用。 ---
在routes/web.php
中,添加:
Route::get('/{vue_capture?}', function () {
return view('welcome');
})->where('vue_capture', '[\/\w\.-]*');
這有助於 Laravel 捕獲 Vue 生成的 URL,並且是設置歷史模式時的路由解決方案,正如您所看到的那樣。
export default new Router({
mode: 'history',
routes
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.