因此,我试图通过建立一个带有laravel vue vue路由器和vuex的SPA。
我的问题是,不管我做什么,路由器视图都没有呈现,我在这里开始失去希望,它只显示来自vue组件的Hello消息。
只要我知道代码没有任何错误。
这是我的设置和文件
laravel路由器页面: web.php
Route::get('/{any}', [App\Http\Controllers\AppController::class, 'index'])->where('any', '.*');
home.blade.php:
@extends('layouts.app')
@section('content')
<App></App>
@endsection
这是我的vue文件
app.js:
import Vue from 'vue';
import router from './router'
import App from './components/App'
require('./bootstrap');
const app = new Vue({
el: '#app',
components: { App },
router
});
router.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import ExampleComponent from './components/ExampleComponent'
Vue.use( VueRouter )
export default new VueRouter( {
mode: 'history',
router: [
{ path: '/', component: ExampleComponent }
]
} )
App.vue文件
<template>
<div class="content">
<h1>Hello</h1>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
ExampleComponenet.vue
<template>
<div>
<h1>This is the Example Component</h1>
</div>
</template>
我得到的OUT 是加载App.vue组件,但<router-view></router-view>
呈现为html注释<!---->
Hello
<!---->
发布于 2020-10-19 07:32:10
我尝试在代码框中重新创建您的代码,结果发现您定义的路线是错误的。与router
不同,您必须在router.js
上使用routes
https://codesandbox.io/s/proud-leftpad-fwtf7?file=/src/router.js
在您的app.js
中,您告诉Vue应用程序使用id为app
的元素挂载,因此
{
el: "#app",
components: ...
}
但是在你的home.blade.php
上你没有任何<div id="app"></div>
。
它可能存在于您的layouts.app
中,但您没有包括它。如果它不在那里,那就是问题所在。
我也不知道你是怎么宣布你在拉拉维尔的路线的:
Route::get('/{any}', [App\Http\Controllers\AppController::class, 'index'])->where('any', '.*');
通常看起来是:
Route::get('/{any}', 'SpaController@index')->where('any', '.*');
发布于 2020-10-19 07:54:04
好吧,请试试这个。
router: [
{ path: '/example', component: ExampleComponent }
]
然后访问URL "http://localhost/exmaple“,看看它是否正确工作。
https://stackoverflow.com/questions/64430317
复制相似问题