【问题标题】:add <tr><td> tag happen trouble using vue.js添加 <tr><td> 标签在使用 vue.js 时出现问题
【发布时间】:2017-06-10 05:39:28
【问题描述】:

我有一个表,当我创建数据时它会更新

我想用 Vue.js 来做

所以我去看看Vue.js Components 并尝试

<div id="app1">
<table class="table table-bordered">
    <tr>
        <td class="active">name</td>
        <td class="active">pirce</td>
    </tr>
    <my-trtd></my-trtd>        
</table>

JS

Vue.component('my-trtd', {
                        template: '<tr><td>' + 1 + '</td>' +
                                      '<td>' + 2 + '</td></tr>'
                    })
                    new Vue({
                        el: '#app1'
                    })

结果

<div id="app1">
<tr>
    <td>1</td>
    <td>2</td>
</tr>
<table class="table table-bordered">
    <tbody>
        <tr>
            ..
        </tr>
    </tbody>
</table>

它可以工作。然而,不是我想要的

这是我消耗的结果

<div id="app1">
<table class="table table-bordered">
    <tbody>
        <tr>
            <td class="active">name</td> 
            <td class="active">pirce</td>
        </tr>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
    </tbody>
</table>

如何解决?

【问题讨论】:

    标签: javascript vue.js vue-component


    【解决方案1】:

    试试这个,就像在这个answer中使用的那样:

    <div id="app1">
      <table class="table table-bordered">
          <tr>
              <td class="active">name</td>
              <td class="active">pirce</td>
          </tr>
          <template>
             <my-trtd></my-trtd>        
          </template>
      </table>
    </div
    

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2015-02-11
      • 2019-08-05
      • 1970-01-01
      相关资源
      最近更新 更多