gpt4 book ai didi

Laravel 6.1 未加载 Vue

转载 作者:行者123 更新时间:2023-12-04 10:45:52 24 4
gpt4 key购买 nike

我刚刚重新安装了 Laravel 6.1 并运行

composer require laravel/ui
php artisan ui vue
npm install && npm run dev

但是在浏览器中查看我的页面时,我发现 Vue 组件没有显示,甚至根本没有加载 Vue。我的 DOM 中有以下错误。

enter image description here

这些是Vue没有加载的原因吗?我该如何解决它们?网址应为 http://localhost/laravel_applications/webgame/public/css/app.csshttp://localhost/laravel_applications/webgame/public/js/app.js我怎样才能改变这个?我在 Xammp 上运行它,它位于 /laravel_applications/webgame 下的 htdocs 文件夹中。 .我尝试将 env 文件中的 APP_URL 更改为
APP_URL=http://localhost/laravel_applications/webgame/public

但这没有用。

Vue 安装在我的项目中,我的 app.js 看起来像这样
require('./bootstrap');

window.Vue = require('vue');
import Vue from 'vue';

// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

Vue.component('application', require('./components/application.vue').default);

const app = new Vue({
el: '#app',
});

我有一个看起来像这样的 components/application.vue
<template>
<div>
Test
</div>
</template>

<script>
export default {

}
</script>

<style>

</style>

还有一个看起来像这样的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>SPA</title>
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<link rel="stylesheet" href="{{ mix('css/app.css') }}" />
<script defer src="{{ mix('js/app.js') }}"></script>
</head>
<body>
<div id="app">
<application></application>
</div>
</body>
</html>

我的 package.json 看起来像这样
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "7.*",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"vue-router": "^3.1.3"
}
}

这是我的混合文件
const mix = require('laravel-mix');

/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/

mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');

最佳答案

你不需要放
APP_URL=http://localhost/laravel_applications/webgame/public
laravel 有助手 asset()指向public laravel 的文件夹,因此您可以通过 asset() 加载公共(public)目录中的任何内容功能

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SPA</title>
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<link rel="stylesheet" href="{{ asset('css/app.css') }}" />
<script defer src="{{ asset('js/app.js') }}"></script>
</head>
<body>
<div id="app">
<application></application>
</div>
</body>
</html>

引用链接 https://laravel.com/docs/master/helpers#method-asset

关于Laravel 6.1 未加载 Vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59710552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com