• readonly 是将通过ref 或reactive定义好的数据进行拷贝后变为仅可读的数据,不可进行修改,即无响应
  • 如强制修改 控制台将会报错警告

代码使用如下:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="http://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="root"></div>
</body>
<script>
    Vue.createApp({
        setup(props, context) {
            const {
                reactive,
                readonly
            } = Vue
            let content = reactive(['aa'])
            let content2 = readonly(content)
            setTimeout(() => {
                content[0] = 'bb'
                content2[0] = 'cc'
            }, 2000)
            return {
                content,
                content2
            }
        },
        template: '<div>{{content[0]}}</div>'
    }).mount('#root')
</script>

</html>

Logo

前往低代码交流专区

更多推荐