Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js表在外部呈现_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

Vue.js表在外部呈现

Vue.js表在外部呈现,vue.js,vuejs2,vue-component,Vue.js,Vuejs2,Vue Component,我正试图渲染一张桌子。数据是动态的,来自一个数组。它工作正常,除了:表格内容在页面顶部的表格外部呈现 我想把它放在桌子里面。有人能帮忙吗 这是代码的外观: Vue.js: Vue.component('word', { props: ['word-list'], template: '#word-template' }); new Vue({ el: '#root' }); HTML: 钥匙 价值 @{{key}} @{{value}} 注意:这是与La

我正试图渲染一张桌子。数据是动态的,来自一个数组。它工作正常,除了:表格内容在页面顶部的表格外部呈现

我想把它放在桌子里面。有人能帮忙吗

这是代码的外观:

Vue.js:

Vue.component('word', {

    props: ['word-list'],

    template: '#word-template'


});

new Vue({
    el: '#root'

});
HTML:


钥匙
价值
@{{key}}
@{{value}}

注意:这是与Laravel一起使用的,这就是为什么有@before双花括号

您不能在Vue的模板中定义组件的模板。你需要把它搬到外面去


钥匙
价值
@{{key}}
@{{value}}
如果将组件的模板保留在根的模板中,则根将编译组件的模板作为其自己模板的一部分

<div id="root">

    <word :word-list="{{json_encode($commonWords) }}"></word>

                <template id="word-template">

                    <table class="table">
                        <thead>

                            <tr>
                                <th>Key</th>
                                <th>Value</th>
                            </tr>
                        </thead>

                        <tbody>

                            <tr v-for="(value, key) in wordList" :wordList="wordList">

                                <td> @{{ key }} </td>
                                <td> @{{ value }} </td>

                            </tr>

                        </tbody>

                    </table>

                </template>


</div>
<div id="root">
  <word :word-list="{{json_encode($commonWords) }}"></word>
</div>

<template id="word-template">
  <table class="table">
    <thead>
      <tr>
        <th>Key</th>
        <th>Value</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(value, key) in wordList" :wordList="wordList">
        <td> @{{ key }} </td>
        <td> @{{ value }} </td>
      </tr>
    </tbody>
  </table>
</template>