だから私はlaravelvuevue-routerとvuexでSPAを構築することでSPAについて学ぼうとしています。
私の問題は、私が何をしてもrouter-viewがまったくレンダリングされず、ここで希望を失い始めており、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のPUT私が得たことは、App.vueコンポーネントの負荷ですが、<router-view></router-view>
HTMLコメントとしてレンダリング<!---->
Hello
<!---->
codesandboxでコードを再作成しようとしましたが、ルートを間違って定義していることがわかりました。router
あなたの代わりにあなたに使用する必要routes
がありますrouter.js
https://codesandbox.io/s/proud-leftpad-fwtf7?file=/src/router.js
あなたの中でapp.js
あなたはVueアプリにapp
このようにIDを持つ要素にマウントするように言っています
{
el: "#app",
components: ...
}
しかし、あなたにhome.blade.php
は何もありません<div id="app"></div>
。
それはあなたに存在するかもしれlayouts.app
ませんが、あなたはそれを含めませんでした。それがない場合は、それが問題です。
Laravelでルートをどのように宣言したかもわかりません:
Route::get('/{any}', [App\Http\Controllers\AppController::class, 'index'])->where('any', '.*');
通常は次のようになります。
Route::get('/{any}', 'SpaController@index')->where('any', '.*');
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加