Vue 组件问题

//main.js
var vm = new Vue({
        el: '#test',
        components : {
            time_ : require('./components/time_.vue'),
        },
        data: {
            // now_date: now_date,
            test: "hello world"
        },
        ready: function(){
            console.log("12312");
        }
    });
    
//test.html
<!DOCTYPE HTML>
<html>
    <head>
        <link rel="stylesheet" href="reset.css">
        <script src="./build/js/vue.js"></script>
        <script src="./build/js/index.js"></script>
    </head>
    <body>
<!--         <div id="te"> -->
            <div id="test">
                <time_></time_>
            </div>
        <!-- </div> -->
    </body>
</html>

//time_.vue
<template>
            <ul>
                <li>{{test}}</li>
            </ul>
</template>

<script>
// import time from './src/components/time_.vue'
    export default {
        data :function(){
            return {
                test : '',
            }
        },
        ready : function(){
            console.log("test");
        }
        // props :['now_date'],
        // computed:{}
    }
</script>

用webpack打包。然后出现如下所示错误提示,需要在webpack.config.js里resolve下的alias设置什么吗?还是有什么东西没有设置。
出现错误提示:[Vue warn]: Failed to mount component: template or render function not defined.
(found in root instance)

阅读 5k
5 个回答

解决了,在入口文件main.js里面将import Vue from 'vue'换成import Vue from 'vue/dist/vue.common.js'就行了,谢谢大家,手动比拳。详情见此链接

你用的什么vue版本,如果是2.x看这里,
但是2.0已经没有 ready 方法了

入口文件没有定义template或者声明render函数

例,

//init
var app = new Vue({
    render: function (h) {
      return h(App);
    }
}).$mount('#app');
Vue.extend({                                                                     
    components: {                            
        time_ : require('./components/time_.vue'),
    }                                        
})                                           

用的是 runtime only 的 Vue?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题