laravel - 停止在 Laravel 中渲染 Vue 组件
问题描述
我有新安装的 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在我的应用程序中呈现?
解决方案
在app.js
引导程序包含后删除所有内容,然后使用npm run dev
.
然而,默认情况下,Laravel 对 Vuejs 不做任何事情。因为它在带有 id 的页面上没有 html 元素#app
。检查您的resources/views
目录,默认刀片文件是welcome.blade.php
.
确切地说,流程:
- 您的路由文件指示如何处理请求以及到哪个控制器
- 负责路由的控制器将(可能)提供刀片视图
- 刀片视图将被解析,如果它有一个
#app
元素并将app.js
Vue 绑定到#app
Vue 将接管。
https://github.com/laravel/laravel/blob/master/resources/views/welcome.blade.php
推荐阅读
- c# - 如何将文本从 Form1 中的 textBox 传输到 Form2 中的标签
- javascript - Zxing Android 应用程序无法从网站打开
- javascript - 如何在 gulp-rename 和 gulp-uglify 的相同路径或 dest 中创建一个 min 文件?
- swiftui - 点击和长按无法正常工作
- c# - 使用 iTextSharp c# 在 PDF 中添加值(例如 PDF 标题和正文内容)
- networking - DDS 可以通过 Internet 用于在线游戏吗?
- c++ - 为什么在二叉树或二叉搜索树中使用 morris 遍历而不是递归?
- reactjs - 用于验证反应组件名称上的帕斯卡大小写的 Eslint 规则(仅适用于 .tsx 扩展名)
- php - 在 Wordpress 短代码中使用 Twig 变量
- ios - SwiftUI 以异步方式加载很长的列表