首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue模板未渲染(控制台中无错误)

问Vue模板未渲染(控制台中无错误)
EN

Stack Overflow用户
提问于 2019-10-08 21:20:07
回答 1查看 822关注 0票数 2

我目前正在尝试编写多个.vue文件,稍后我可以使用Laravel的Blade Syntax将其用作模板标签。

我写下了在我的app.js中使用vue的必要行,注册了我的组件以便使用我文件的语法。

但是,我运行npm run dev成功且没有错误。然而,我的Vue没有被渲染&& Chrome Dev控制台没有显示错误(没有检测到Vue.js)

app.js

代码语言:javascript
复制
require('./bootstrap');

// import Vue from 'vue'
// import VueRouter from 'vue-router'
// import TriviaGame from './components/TriviaGame.vue'
// import Dashboard from './components/Dashboard.vue';

Window.vue = require('vue');


// Vue.use(VueRouter)

// Vue.config.productionTip = false
Vue.component('trivia-game', require('./components/TriviaGame.vue')).default;
Vue.component('dashboard', require('./components/Dashboard.vue')).default;

const app = new Vue({
    el:'#app'
})


// const routes = [
//     { path: '/', component: Dashboard },
//     { path: '/trivia', component: TriviaGame }
// ]

// const router = new VueRouter({
//     mode: 'history',
//     routes
// })

// new Vue({
//     router,
//     render: h => h(Dashboard)
// }).$mount('#app')

welcome.blade.php

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
        <script src="{{asset('js/app.js')}}"></script>
        <title>Vue SPA</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">

        <!-- Styles -->
        <style>
            html, body {
                background-color: #fff;
                color: #636b6f;
                font-family: 'Nunito', sans-serif;
                font-weight: 200;
                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: 13px;
                font-weight: 600;
                letter-spacing: .1rem;
                text-decoration: none;
                text-transform: uppercase;
            }

            .m-b-md {
                margin-bottom: 30px;
            }
        </style>
    </head>
    <body>
       <p>This is just an example</p>
       <div id="app">
       <trivia-game></trivia-game>


        </div>

    </body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2019-10-08 21:39:14

你在头部的app.js在dom解析之前就被执行了(还没有#app )。

要么把它移到身体的底部

代码语言:javascript
复制
...
    <script src="{{asset('js/app.js')}}"></script>
</body>

或添加延时

代码语言:javascript
复制
<head>
    <script src="{{asset('js/app.js')}}" defer></script>
</head>

或者在dom内容加载事件中添加vue代码。

代码语言:javascript
复制
window.addEventListener("load", function(event) {
    new Vue({...})
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58287210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档