熟悉 Vue ?你能解释这个死循环吗?

栏目: JavaScript · 发布时间: 7年前

内容简介:把下面的代码拷到你的 html 文件,在浏览器打开你会看到控制台报了死循环的错,知道为什么吗?

把下面的代码拷到你的 html 文件,在浏览器打开你会看到控制台报了死循环的错,知道为什么吗?

<body>
    <div id="app">
        <child-comp v-for="i in [1]" :key="Math.random()" :sub-prop="parentData"></child-comp>
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
        Vue.component('child-comp', {
            props: {
                subProp: {}
            },
            data() {
                return {
                    subData: []
                };
            },
            template: '<div></div>',
            computed: {
                subComputed() {
                    return '222';
                }
            },
            created() {
                console.log(this.subComputed);
                this.subData.push(1);
            }
        });
        vm = new Vue({
            el: '#app',
            data() {
                return {
                    parentData: 'hello world'
                };
            }
        })
    </script>
</body>
复制代码

以上所述就是小编给大家介绍的《熟悉 Vue ?你能解释这个死循环吗?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Remote

Remote

Jason Fried、David Heinemeier Hansson / Crown Business / 2013-10-29 / CAD 26.95

The “work from home” phenomenon is thoroughly explored in this illuminating new book from bestselling 37signals founders Fried and Hansson, who point to the surging trend of employees working from hom......一起来看看 《Remote》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器