Vue 数据冻结 Object.freeze


Vue 数据冻结  Object.freeze

情景: 页面上常量或者对象不想让修改,只是读取,这时候需要数据冻结   Object.freeze, demo如下

<script>
    import Vue from 'vue';
    export default {
        data() {
            return {
                f33: Object.freeze({
                    foo: "bar",
                    da: "fei",
                    hello: "world",
                })
            }
        },
        created(){
            console.log(this.f33);
            // this.f33.hello = "new hello"; // 这里报错
            // this.f33.val = "dddddddd"; // 这里也会报错
        },
    }
</script>

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM