简体   繁体   English

使用 Vue.js 的 Laravel 6.6 项目中未显示模板

[英]Template not showing in my Laravel 6.6 project with Vue.js

I made the basic installation from Vue.JS in my Laravel project, this is my package.json我在我的 Laravel 项目中从 Vue.JS 进行了基本安装,这是我的 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": "^5.0.1",
        "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"
    }
}

So I run this code that everyone does after installation npm run install && npm run dev for the mix from Laravel generate the files, every tutorial say that I must put this in the footer from my main file所以我运行这段代码,每个人在安装npm run install && npm run dev 后从 Laravel 混合生成文件,每个教程都说我必须把它放在我的主文件的页脚中

<script src="{{ asset('js/app.js') }}"></script>

And always say that the file doesn't exist, it is true because when I run this command from mix above, this simple make a js and a css folder in a new public folder, this is the right approach?并且总是说该文件不存在,这是真的,因为当我从上面的 mix 运行这个命令时,这个简单的在一个新的公共文件夹中创建一个 js 和一个 css 文件夹,这是正确的方法吗? because I don't see any tutorial that this command makes a public folder, see the image below:因为我没有看到任何说明此命令创建公共文件夹的教程,请参见下图:

在此处输入图片说明

So when I explicitly put this path:因此,当我明确放置此路径时:

<script src="{{ asset('public/js/app.js') }}"></script>

My Vue.js is loaded and I see the default text from Vue.js in console, but when I put the template from this file TesteFood.vue我的 Vue.js 已加载,我在控制台中看到来自 Vue.js 的默认文本,但是当我将此文件中的模板放入TesteFood.vue

<template>
    <h1>Testando VUE</h1>
</template>

Is not showing and I make this command too npm run watch no success.没有显示,我也使这个命令npm run watch没有成功。

尝试mix助手功能:

<script src="{{ mix('js/app.js') }}"></script>

I simply reinstall all my Laravel and install Vue.js and don't move the public folder and all is working fine.我只需重新安装所有 Laravel 并安装 Vue.js 并且不移动公共文件夹,一切正常。

Thank you all!谢谢你们!

when you install the laravel 6, then run this command composer require laravel/ui --dev for integrating all vue js dependencies, then create your component and register that in app.js file like this :当您安装 laravel 6 时,然后运行此命令composer require laravel/ui --dev以集成所有 vue js 依赖项,然后创建您的组件并将其注册到 app.js 文件中,如下所示:

Vue.component('teste-food', require('./components/TesteFood.vue')); Vue.component('teste-food', require('./components/TesteFood.vue')); and then run npm run dev for compiling once the codes or npm run watch for compiling anythime you add some vue.js file or sass in your porject.然后运行npm run dev进行编译,一旦代码或npm run watch进行编译,您可以在项目中添加一些 vue.js 文件或 sass。 In this steps you should see your component.在此步骤中,您应该会看到您的组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM