如何在Laravel 5.4中加载Vue组件? [英] how do I load a Vue component in Laravel 5.4?
问题描述
我已经运行npm run watch并收到了消息
I've run npm run watch and received the message
This dependency was not found:
* in ./resources/assets/js/app.js
To install it, you can run: npm install --save
所以我运行了npm install --save,但仍然收到相同的消息.
So I ran npm install --save but still get the same message.
据我了解,我需要npm run或npm run watch才能在Laravel中加载Vue文件.
From my understanding, I need npm run or npm run watch to load the Vue files in Laravel.
例如,在"resources/assets/js/components/Example.vue"文件中,我对其进行了编辑,但是当我加载"resources/views/welcome.blade.php"文件时,该文件如下,则不会加载Example.vue文件中的更新.
For example, in 'resources/assets/js/components/Example.vue' file, I made edits to it but when I load up 'resources/views/welcome.blade.php' file, which I have as follows, the update from Example.vue file does not load.
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@if (Auth::check())
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ url('/login') }}">Login</a>
<a href="{{ url('/register') }}">Register</a>
@endif
</div>
@endif
<div id="app">
<example></example>
</div>
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
<a href="https://laravel.com/docs">Documentation</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
<script src='js/app.js'></script>
</body>
</html>
(我只在脚本src链接和div中添加了"app" ID和"example"组件)
(I only added in the script src link and the div with the 'app' id and the 'example' component)
我该怎么做才能加载对Example.vue文件所做的更改?之后,我还需要在Laravel的Vue.js中为我的应用程序创建新组件.
What must I do to load the changes made to the Example.vue file? After this, I need to create new components in Vue.js in Laravel as well for my application.
推荐答案
您需要运行:
npm install
然后:
npm run dev
这篇关于如何在Laravel 5.4中加载Vue组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!