doushua7737 2019-06-18 14:51
浏览 60
已采纳

父组件外部的Vue内容呈现

When I load a vue component inside a @foreach tag it gets rendered first, outside of its parent component.

 //view 
     <div class="contenido" style="padding-top:5%">

         <table class="table">
                <thead class="thead-dark">
                    <tr>
                        <th class="col-md-8">Nombre descripción general</th>
                        <th class="col-md-2">Actualizar</th>
                        <th class="col-md-2">Consultar</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($descs as $desc)
                        <tab-descgen desc-nombre = "{{ $desc -> nombre }}" desc-id = "{{ $desc -> id }}"></tab-descgen>
                @endforeach
                </tbody>

            </table>

   //vue component
   <template>
    <tr >
         <td>{{ this.descNombre }}</td>
     <td><i style="font-size:30px;" class="fa fa-edit float-center"></i> 
 </td>
     <td><i style="font-size:30px;" class="fa fa-arrow-circle-right 
   float-center"></i></td>
  </tr>
   </template>

  <script>
    export default {
       props:['descNombre', 'descId'],

When this gets rendered the table rows inside the vue component will be rendered above the header, and I don't quite understand why. I want to know if I'm missing something.

  • 写回答

3条回答 默认 最新

  • dongmiyi8220 2019-06-18 15:01
    关注

    Even ignoring all the server-side stuff, this won't work:

    <tbody>
      <tab-descgen></tab-descgen>
    </tbody>
    

    It'd be fine in a single-file component but if this markup makes it to the browser (as it will in your case) it'll rip the tab-descgen out of the table before Vue gets anywhere near it.

    You'd need to use is to work around it:

    <tbody>
      <tr is="tab-descgen"></tr>
    </tbody>
    

    It's explained here in the docs:

    https://vuejs.org/v2/guide/components.html#DOM-Template-Parsing-Caveats

    In short, only tr elements are allowed as direct children of tbody, anything else gets pulled out. The workaround is to use a tr and then let Vue know what you really wanted using is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)