Heim  >  Fragen und Antworten  >  Hauptteil

Vue <Skripteinstellungen>-Reaktivität funktioniert nicht

<p>Ich probiere die <code><script setup></code>-Syntax aus und frage mich, warum die Reaktivität nicht funktioniert. Was ist hier los? </p> <pre class="brush:js;toolbar:false;"><template> <button @click="changeButtonText">{{ buttonText }}</button> </template> <Skript-Setup> { ref } aus 'vue' importieren let buttonText = ref("Foo") Funktion changeButtonText() { buttonText = "Bar" } </script> </pre> <p>Versuchen Sie es, ohne ref() zu verwenden. Versuchen Sie es mit <code>buttonText = ref("Bar")</code>. Keine Auswirkung</p>
P粉029327711P粉029327711409 Tage vor350

Antworte allen(1)Ich werde antworten

  • P粉518799557

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

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

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

    Antwort
    0
  • StornierenAntwort