这篇文章中有一个例子。它说正常的物体不会有“反应性”。
我在这个codesandbox中做了测试,发现对普通对象(甚至是普通字符串)的改变可以自动改变视图。
<template>
{{ personName }} <!-- will change to Amy, why? -->
{{ person.name }} <!-- will change to Amy, why? -->
{{ personRef.name }}
{{ personReactive.name }}
<button @click="changeName('Amy')">changeName</button>
</template>
<script setup>
import { ref, reactive } from "vue";
let personName = "John";
const person = { name: "John" };
const personRef = ref({ name: "John" });
const personReactive = reactive({ name: "John" });
const changeName = (name) => {
personName = name;
person.name = name; …Run Code Online (Sandbox Code Playgroud)