The vue child component data has changed. why hasn't the parent component changed?

is it not true that the data of the parent component will be affected when the child component of the computing property is changed without the use of the parent-child communication? Why is this child component + 1 and the parent component is still 10? Or is the example I wrote wrong?

<!DOCTYPE html>
<html>
<head>
   <title></title>
   <style type="text/css">
   </style>
   <script src="vue.js"></script>
   <script type="text/javascript">
      window.onload=function(){
         var user={
            template:"-sharpmy_div",
            props:["message"],
            methods:{
              add(){
                this.messagePP;
                this.$emit("increment1");
              }
            }
         }
         new Vue({
               el:"-sharpapp",
               data:{
                test:10
               },
               components:{
                  "user":user
               },
               methods:{
                  incrementTotal: function () {
                      alert(this.test);
                  }
               }
         })
      }
   </script>
</head>
<body>
<template id="my_div">
  <div>
    <h3>{{message}}</h3>
    <button @click=add()></button>
  </div>
</template>
<div id="app">
    <user :message="test" v-on:increment1="incrementTotal"></user>
</div>
</body>
</html>
Apr.14,2021

if a single data stream wants to update the parent component, you dispatch the value that needs to be updated back to the parent component, and then the parent component does the update logic according to the returned value (or not).

in your case, the logic of updating message can be put directly into the parent component, and then the child component only renders according to the passed prop, and then the dispatch event returns to the parent component, and then in the callback function of the parent component, update the vm passed into the child component.


The example written by

is problematic.
Let's get this straight:
parent component: test (10) , passed to child components via props one-way -> test (10), message (10) ,

child components: whenever click , message is + 1, message is not an object / array, so it has no effect on test of the parent component-> test (10), message (11) .

The

child component triggers the increment1 event of the parent component, and the parent component executes alert (this.test); -> test (10), message (11)
this process does not change the parent component test . So it's still 10.

The

implementation changes the test of the parent component by doing this:

// 1, 
add(){
    this.messagePP;
    this.$emit('increment1',this.message);
  }
...
 incrementTotal: function (message) {
    this.test= message;
    alert(this.test);
      }
// 2. +1
add(){
    this.messagePP;
    this.$emit('increment1');
  }
...
 incrementTotal: function () {
    this.testPP;;
    alert(this.test);
    }

There is something wrong with the example written by

. Do not directly manipulate the message passed by the parent component. Take a look at ide/components-props.html-sharp%E5%8D%95%E5%90%91%E6%95%B0%E6%8D%AE%E6%B5%81" rel=" nofollow noreferrer "> document

.

you can set this in child components

prop:['message'],
data(){
    msg:this.message//,prop
},
methods:{
    add(){
        this.msgPP;
        this.$emit('add',this.msg);
    }
}

listen for add in the parent component, and then update the test value of the parent component.


you can use the .sncy modifier if you want the data passed in by the child parent component Synchronize to change Synchronize. Or use vuex instead of passing parameters

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36091-2b345.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36091-2b345.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?