首页  >  问答  >  正文

Vue <脚本设置> 反应性不起作用

<p>我正在尝试 vue 中的 <code><script setup></code> 语法,并想知道为什么反应性不起作用。这里出了什么问题?</p> <pre class="brush:js;toolbar:false;"><template> <button @click="changeButtonText">{{ buttonText }}</button> </template> <script setup> import { ref } from 'vue' let buttonText = ref("Foo") function changeButtonText() { buttonText = "Bar" } </script> </pre> <p>尝试不使用 ref()。 尝试使用 <code>buttonText = ref("Bar")</code>。没有效果</p>
P粉029327711P粉029327711409 天前344

全部回复(1)我来回复

  • P粉518799557

    P粉5187995572023-09-06 15:49:26

    在你的函数中你必须改变 buttonText = "Bar" 到 buttonText.value="Bar"

    有关反应性的更多信息,请参阅:https://vuejs.org/api/ reactivity-core.html#ref

    回复
    0
  • 取消回复