我有新安装的Laravel应用程序我也安装了npm,现在我尝试加载此文件的每个页面都将加载ExampleComponent.vue
app.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('example-component', require('./components/ExampleComponent.vue'));
const app = new Vue({
el: '#app'
});
ExampleComponent.vue
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example Component</div>
<div class="card-body">
I'm an example component.
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log('Component mounted.')
}
}
</script>
由于我没有计划使用VueJs,我还需要查看我创建的实际页面,如何阻止VueJs 在我的应用程序中呈现?
答案 0 :(得分:2)
在app.js
中删除引导程序后的所有内容,然后使用npm run dev
重新编译。
但是,默认情况下,Laravel对Vuejs没有任何作用。因为页面上没有标识为#app
的html元素。检查您的resources/views
目录,默认刀片文件为welcome.blade.php
。
确切地讲述流程:
#app
元素并且app.js
将Vue绑定到#app
Vue将接管,则会解析刀片视图。https://github.com/laravel/laravel/blob/master/resources/views/welcome.blade.php
答案 1 :(得分:0)
如果您没有使用vue.js,则可以安全地从刀片中删除#app
div标签。另外,不要忘记删除脚本以加载app.js
。此脚本是不必要的,因为它主要在您仅使用vue.js时使用。
现在,您将使用普通的php文件(使用刀片语法)。
希望这有帮助。