我想要渲染 Vue.js 代码,但无法在 LARAVEL 5.7 中工作
我的app.js代码:
require('./bootstrap');
window.Vue = require('vue');
Vue.component('hello-world-component', require('./components/HelloWorld.vue'));
const app = new Vue({
el: '#app'
});
和新文件 HelloWorld.vue :
<template>
<div class="container">
Hello Laravel + Vue!
</div>
</template>
<script>
export default {
mounted() {
console.log('Component mounted.')
}
}
</script>
还有welcome.blade.php:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Laravel</title>
</head>
<body>
<div class="content">
<div class="title m-b-md">
<hello-world-component></hello-world-component>
</div>
</div>
</body>
</html>
当我运行这个命令时,
sudo npm run dev
结果:
DONE Compiled successfully in 6224ms 7:16:51 AM
Asset Size Chunks Chunk Names
/js/app.js 1.38 MB 0 [emitted] [big] /js/app
/css/app.css 198 kB 0 [emitted] /js/app
但是当我连接索引页面时,没有显示我的 HelloWorld.Vue 代码。
我不知道出了什么问题?
最佳答案
您需要一个 id 为 app
的元素来挂载。例如:
html
<body>
<div id="app"></div>
</body>
<script src="/js/app.js"></script>
js
const app = new Vue({
el: '#app',
template: '<hello-world-component></hello-world-component>'
});
关于laravel - Vue.js + Laravel5.7 'Hello World' 测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53533820/