The Vue button binds the data. After the click event is triggered, the button data remains unchanged.

I am a beginner in Vue. When I was reading about v-once today, I used the button to bind a data.

after clicking the button, the data bound by v-once has not changed, but the button book has not changed either. I bound a new button. Click this new button, and the data of the previous button changes

related codes

/ / Please paste the code text below (do not replace the code with pictures)

<div id="app2">
    <!-- text -->
  <button @click="change">{{text}}</button>
    <p v-once>{{text}}

{{text}}

<!-- {{text}} --> <button @click="change"></button> </div> <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script> <script> new Vue({ el:"-sharpapp2", data:{ text:"" }, methods:{ change:function(){ this.text=""; } } }) </script>

what result do you expect? What is the error message actually seen?

I thought that only the data bound by v-once would not change after clicking the test button, and the rest would change.
but after clicking, I found that the test button has not changed, because I am a beginner, do not understand, hope to get the guidance of the god, thank you

clipboard.png

Mar.25,2021

It's no problem that

copied your code?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app2">
        <!-- text -->
      <button @click="change">{{text}}</button>
        <p v-once>{{text}}

{{text}}

<!-- {{text}} --> <button @click="change"></button> </div> <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script> <script> new Vue({ el:'-sharpapp2', data:{ text:'' }, methods:{ change:function(){ this.text=''; } } }) </script> </body> </html>

clipboard.png


so you want to change that? now you just want to start the change event. Apart from binding v-once, how much else will change to "Ah really fell in love with Ah Qiang"? is that not what you imagined?

Menu