dongnu4254 2017-10-04 11:43 采纳率: 100%
浏览 945
已采纳

使用Vue模板时出错:无法安装组件:未定义模板或渲染功能

I am trying to make some Vue Templates, but i still encounter this error:

Failed to mount component: template or render function not defined.

I found a lot of suggestions that i should include the full Vue to make this work. So i did in the bootstrap.js:

window.Vue = require('vue/dist/vue.common.js');

sadly it didnt help.

Any suggestions?

EDIT:

I think the problem is that i am trying to use an inline-template inside another one:

create.vue:

<script>
    import PartnerData from './PartnerForm.vue';

    export default {

        components: {
            'partnerdata': PartnerData
        },

        data() {
            return {}
        },

        mounted() {
            console.log('hello');
        },

    }
</script>

PartnerForm.vue:

<script>
    export default {

    }
</script>

and this is my form.blade.php

<partnerdata inline-template>

    <div class="ui grid form">

        <div class="two column row">

            <!--COLUMN 1-->
            <div class="column">
...
</partnerdata>

when i just put a template tag in the PartnerForm.vue like this:

<template> HELLO </template>
<script>
    export default {

    }
</script>

Then Hello gets rendered. But if i try to use the form as an inline template i get that error.

  • 写回答

1条回答 默认 最新

  • duanhuren5581 2017-10-04 11:56
    关注

    see the installation instructions from here.

    Vue Installation

    see this part https://vuejs.org/v2/guide/installation.html#Explanation-of-Different-Builds

    and this https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only

    It states the following configurations

    Webpack

    if you are using laravel

    module.exports = {
      // ...
      resolve: {
        alias: {
          'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
        }
      }
    }
    

    Rollup

    const alias = require('rollup-plugin-alias')
    rollup({
      // ...
      plugins: [
        alias({
          'vue': 'vue/dist/vue.esm.js'
        })
      ]
    })
    

    Browserify

    Add to your project’s package.json:
    {
      // ...
      "browser": {
        "vue": "vue/dist/vue.common.js"
      }
    }
    

    EDIT

    after installing laravel 5.5 see packages.json

    .....
    "devDependencies": {
        "axios": "^0.16.2",
        "bootstrap-sass": "^3.3.7",
        "cross-env": "^5.0.1",
        "jquery": "^3.1.1",
        "laravel-mix": "^1.0",
        "lodash": "^4.17.4",
        "vue": "^2.1.10"
    }
    

    }

    to install the dependencies

    run npm install 
    

    now you can use laravel mix

    see packages.json again

    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    

    that means now you can run those commands with 'npm run'. example:npm run dev,

    see the command config file

    config=node_modules/laravel-mix/setup/webpack.config.js
    

    which loads this config file

    https://github.com/JeffreyWay/laravel-mix/blob/v1.0.0/src/builder/WebpackConfig.js

    in this file you will see that it has been already configured in laravel mix for you. following method of above file does that for you.

    /**
     * Build the resolve object.
     */
    buildResolving() {
        let extensions = ['*', '.js', '.jsx', '.vue'];
    
        if (Config.typeScript) {
            extensions.push('.ts', '.tsx');
        }
    
        this.webpackConfig.resolve = {
            extensions,
    
            alias: {
                'vue$': 'vue/dist/vue.common.js'
            }
        };
    
        return this;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机