简体   繁体   中英

add <tr><td> tag happen trouble using vue.js

I have a table when I create a data it will update

and I want using Vue.js to do

so I to see Vue.js Components and try

<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'
                    })

result

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

it's can work. However, is not I want

this is my expented result

<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>

How to fix it?

Try it like this, as being used in this 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM