nfgjmzxz 2020-05-22 15:13 采纳率: 0%
浏览 702

Vue组件能否存放在数组中,可以的话怎么去调用

一个网页里的格式是一个父组件读取js里插入的数据,但是不知道具体个数的子组件,
想通过数组用vfor循环调用,出来的结果是子组件的具体代码
如果假设就一个子组件直接调用是正常的,但是放在数组里出来的还是错的

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
        <style type="text/css">
            .aaa{width: 250px;
                height: 190px;

            }
            .bbb{width: 250px;
                height: 190px;
                -webkit-filter: brightness(50%);filter: brightness(50%);
            }
        </style>
    </head>
    <body style="background-image: url(组%209.png);">

        <div id="a">
        <com1></com1>
        <div id="x" v-for="itme in arr">
            {{itme}}
        </div>
        </div>

        <script type="text/javascript">
            var arr = new Array();
            var com1 = {
             template:`<div id=""style="width: 20;">
             <div style="position: relative; width: 250px; height: 190px;white-space: nowrap;margin-left: 30px;border:9px solid #fff;border-top-left-radius: 10px;border-top-right-radius: 10px; border-bottom-left-radius: 10px;border-bottom-right-radius: 10px;">
             <img src="组%209.png" :class="{aaa:y,bbb:n}" @mousedown="dj" @mouseup="dj">
             <span style="position: absolute; top: 60px; left: 54px;"><h2 style="color: aliceblue;" @mousedown="dj" @mouseup="dj"><center>123</center></h2><h4 style="color: aliceblue;"><center>(点击状态)</center></h4></span>
             </div>
             </div>`,
             data:function(){
                 return{
                     y:true,
                     n:false,
                 }
             },
             methods:{
                 dj:function(){
                     this.y = !this.y;
                     this.n = !this.n;

                 }
             }
            }//子组件
             let a =new Vue({
                 el:"#a",
                 components:{
                'com1':com1
                },

                 data:{
                     arr:[com1]
                 }

             })
        </script>






    </body>
</html>
  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器