我正在關注Vue Laravel 的這個簡單的 Crud 教程, Laravel 部分的一切似乎都很好(從創建控制器和模型)看起來很好,但我不能讓 vue 出現在 Laravel 的歡迎刀片中。這是我的代碼:
app.js 檔案
require('./bootstrap');
window.Vue = require('vue');
import App from './App.vue';
import VueAxios from 'vue-axios';
import VueRouter from 'vue-router';
import axios from 'axios';
import { routes } from './routes';
Vue.use(VueRouter);
Vue.use(VueAxios, axios);
const router = new VueRouter({
mode: 'history',
routes: routes
});
const app = new Vue({
el: '#app',
router: router,
render: h => h(App),
});
應用程式.vue 檔案:
<template>
<div class="container">
<h2>Vue app</h2>
<router-view> </router-view>
</div>
</template>
<script>
export default {}
</script>
這是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>Laravel</title>
<style>
body {
font-family: 'Nunito', sans-serif;
}
</style>
</head>
<body class="antialiased">
<div id="app"> </div>
<script src="{{ mix('js/app.js') }}" type="text/javascript"></script>
<h2>The welcome blade</h2>
</body>
</html>
編輯:下面添加的答案,基本上遵循另一個教程
uj5u.com熱心網友回復:
之后查看代碼composer require laravel/ui,php artisan ui vue我發現可能會影響代碼執行的微小變化。最初是 Laravel 設定創建的window.Vue = require('vue').default;,但您的代碼有window.Vue = require('vue')
uj5u.com熱心網友回復:
首先,試試這個:
<script src="{{ asset('js/app.js') }}" defer></script>
其次,您可能需要在 div 中使用 id app 的路由器視圖元素。我不能肯定地說,因為我不知道你的路線。如果上述更改不能解決問題,請添加路由器視圖,如
<div id="app">
<router-view />
</div>
更新
另一件事要嘗試。洗掉這些行
import VueAxios from 'vue-axios';
import axios from 'axios';
Vue.use(VueAxios, axios);
因為您在 bootstrap.js 檔案中有 axios。
并確保控制臺上沒有錯誤訊息。
uj5u.com熱心網友回復:
所以我的安裝程序一定有問題,因為我遵循了另一個教程,現在它的作業視頻
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432674.html
