停止在Laravel中渲染Vue组件

时间:2018-06-15 05:11:16

标签: laravel vue.js

我有新安装的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 在我的应用程序中呈现?

2 个答案:

答案 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文件(使用刀片语法)。

希望这有帮助。