Reactivity in depth in data











up vote
0
down vote

favorite












I need some help. I have a component where I pass a prop and I need to assign a variable from my data to the prop variable, but in a reactive way. I cant modify the child it only accepts Booleans. The problem is that Vue initializates the data, but the disabled attribute isnt reactive. I know that if I pass an object to the disabled attribute that will be reactive, but I cant.



data() {
let editmode = true;

return {
EditMode: editmode,
schema: [
{
disabled: !editmode,
}
]
}
}


In the future I need to edit the value of EditMode and I want to that edit to be passed to my child component. I pass the schema variable to the child.










share|improve this question









New contributor




Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I need some help. I have a component where I pass a prop and I need to assign a variable from my data to the prop variable, but in a reactive way. I cant modify the child it only accepts Booleans. The problem is that Vue initializates the data, but the disabled attribute isnt reactive. I know that if I pass an object to the disabled attribute that will be reactive, but I cant.



    data() {
    let editmode = true;

    return {
    EditMode: editmode,
    schema: [
    {
    disabled: !editmode,
    }
    ]
    }
    }


    In the future I need to edit the value of EditMode and I want to that edit to be passed to my child component. I pass the schema variable to the child.










    share|improve this question









    New contributor




    Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I need some help. I have a component where I pass a prop and I need to assign a variable from my data to the prop variable, but in a reactive way. I cant modify the child it only accepts Booleans. The problem is that Vue initializates the data, but the disabled attribute isnt reactive. I know that if I pass an object to the disabled attribute that will be reactive, but I cant.



      data() {
      let editmode = true;

      return {
      EditMode: editmode,
      schema: [
      {
      disabled: !editmode,
      }
      ]
      }
      }


      In the future I need to edit the value of EditMode and I want to that edit to be passed to my child component. I pass the schema variable to the child.










      share|improve this question









      New contributor




      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I need some help. I have a component where I pass a prop and I need to assign a variable from my data to the prop variable, but in a reactive way. I cant modify the child it only accepts Booleans. The problem is that Vue initializates the data, but the disabled attribute isnt reactive. I know that if I pass an object to the disabled attribute that will be reactive, but I cant.



      data() {
      let editmode = true;

      return {
      EditMode: editmode,
      schema: [
      {
      disabled: !editmode,
      }
      ]
      }
      }


      In the future I need to edit the value of EditMode and I want to that edit to be passed to my child component. I pass the schema variable to the child.







      javascript vue.js






      share|improve this question









      New contributor




      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 8 at 9:40





















      New contributor




      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 8 at 9:27









      Itpalert

      11




      11




      New contributor




      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          The attribute disabled is not reactive because he is not receiving a referenced variable to pass it reference across the data structure, basically you is saying disabled: !true, that evaluated to disabled: false, and "false" is just false, not a reference from the variable because a boolean is not referenceable, a object is (by example, and this is one of reasons to data hook return a object)! And if you change the editmode variable nothing is gona to happen ... Rethink your data structure and edit what your need putting these data in a object to be reactive! Hope it helps.



          If you really need two separated variables, a workaround is use a watcher to detect when editMode changes and populate the changed value to another variable in data..



          <template>
          <div>
          <button @click="change">Change Edit Mode {{editMode}}</button>
          <child-component :isEditing="!schema.disabled"></child-component>
          </div>
          </template>

          <script>
          export default {

          name: "test2",
          components: {

          'child-component': {

          template: "<div>Editing? {{isEditing}}</div>",
          props: {

          isEditing: {

          required: true,
          type: Boolean
          }
          }
          }
          },
          data(){

          return {

          editMode: true,
          schema: {

          disabled: false
          }
          }
          },
          methods: {

          change(){

          this.editMode = !this.editMode;
          }
          },
          watch: {

          editMode(n){

          this.schema.disabled = !n;
          }
          }
          }
          </script>





          share|improve this answer






























            up vote
            0
            down vote













            Thanks for your response! I think I havent described my problem enough. I understood that a variable isnt referencable only the objects. I post the answer I got in the Vue forum, in the hope I can help someone else, because this solved my problem. Solution



            <template>
            <form-generator :schema="schema">
            </template>

            <script>
            Data() {
            return {
            EditMode: false,
            },
            methods: {
            Edit() {
            this.EditMode = true.
            }
            },
            computed: {
            schema() {
            return [
            {
            type: "MInput",
            disabled: !this.EditMode,
            }
            ]
            }
            },
            </script>





            share|improve this answer










            New contributor




            Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });






              Itpalert is a new contributor. Be nice, and check out our Code of Conduct.










               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204805%2freactivity-in-depth-in-data%23new-answer', 'question_page');
              }
              );

              Post as a guest
































              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              The attribute disabled is not reactive because he is not receiving a referenced variable to pass it reference across the data structure, basically you is saying disabled: !true, that evaluated to disabled: false, and "false" is just false, not a reference from the variable because a boolean is not referenceable, a object is (by example, and this is one of reasons to data hook return a object)! And if you change the editmode variable nothing is gona to happen ... Rethink your data structure and edit what your need putting these data in a object to be reactive! Hope it helps.



              If you really need two separated variables, a workaround is use a watcher to detect when editMode changes and populate the changed value to another variable in data..



              <template>
              <div>
              <button @click="change">Change Edit Mode {{editMode}}</button>
              <child-component :isEditing="!schema.disabled"></child-component>
              </div>
              </template>

              <script>
              export default {

              name: "test2",
              components: {

              'child-component': {

              template: "<div>Editing? {{isEditing}}</div>",
              props: {

              isEditing: {

              required: true,
              type: Boolean
              }
              }
              }
              },
              data(){

              return {

              editMode: true,
              schema: {

              disabled: false
              }
              }
              },
              methods: {

              change(){

              this.editMode = !this.editMode;
              }
              },
              watch: {

              editMode(n){

              this.schema.disabled = !n;
              }
              }
              }
              </script>





              share|improve this answer



























                up vote
                0
                down vote













                The attribute disabled is not reactive because he is not receiving a referenced variable to pass it reference across the data structure, basically you is saying disabled: !true, that evaluated to disabled: false, and "false" is just false, not a reference from the variable because a boolean is not referenceable, a object is (by example, and this is one of reasons to data hook return a object)! And if you change the editmode variable nothing is gona to happen ... Rethink your data structure and edit what your need putting these data in a object to be reactive! Hope it helps.



                If you really need two separated variables, a workaround is use a watcher to detect when editMode changes and populate the changed value to another variable in data..



                <template>
                <div>
                <button @click="change">Change Edit Mode {{editMode}}</button>
                <child-component :isEditing="!schema.disabled"></child-component>
                </div>
                </template>

                <script>
                export default {

                name: "test2",
                components: {

                'child-component': {

                template: "<div>Editing? {{isEditing}}</div>",
                props: {

                isEditing: {

                required: true,
                type: Boolean
                }
                }
                }
                },
                data(){

                return {

                editMode: true,
                schema: {

                disabled: false
                }
                }
                },
                methods: {

                change(){

                this.editMode = !this.editMode;
                }
                },
                watch: {

                editMode(n){

                this.schema.disabled = !n;
                }
                }
                }
                </script>





                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The attribute disabled is not reactive because he is not receiving a referenced variable to pass it reference across the data structure, basically you is saying disabled: !true, that evaluated to disabled: false, and "false" is just false, not a reference from the variable because a boolean is not referenceable, a object is (by example, and this is one of reasons to data hook return a object)! And if you change the editmode variable nothing is gona to happen ... Rethink your data structure and edit what your need putting these data in a object to be reactive! Hope it helps.



                  If you really need two separated variables, a workaround is use a watcher to detect when editMode changes and populate the changed value to another variable in data..



                  <template>
                  <div>
                  <button @click="change">Change Edit Mode {{editMode}}</button>
                  <child-component :isEditing="!schema.disabled"></child-component>
                  </div>
                  </template>

                  <script>
                  export default {

                  name: "test2",
                  components: {

                  'child-component': {

                  template: "<div>Editing? {{isEditing}}</div>",
                  props: {

                  isEditing: {

                  required: true,
                  type: Boolean
                  }
                  }
                  }
                  },
                  data(){

                  return {

                  editMode: true,
                  schema: {

                  disabled: false
                  }
                  }
                  },
                  methods: {

                  change(){

                  this.editMode = !this.editMode;
                  }
                  },
                  watch: {

                  editMode(n){

                  this.schema.disabled = !n;
                  }
                  }
                  }
                  </script>





                  share|improve this answer














                  The attribute disabled is not reactive because he is not receiving a referenced variable to pass it reference across the data structure, basically you is saying disabled: !true, that evaluated to disabled: false, and "false" is just false, not a reference from the variable because a boolean is not referenceable, a object is (by example, and this is one of reasons to data hook return a object)! And if you change the editmode variable nothing is gona to happen ... Rethink your data structure and edit what your need putting these data in a object to be reactive! Hope it helps.



                  If you really need two separated variables, a workaround is use a watcher to detect when editMode changes and populate the changed value to another variable in data..



                  <template>
                  <div>
                  <button @click="change">Change Edit Mode {{editMode}}</button>
                  <child-component :isEditing="!schema.disabled"></child-component>
                  </div>
                  </template>

                  <script>
                  export default {

                  name: "test2",
                  components: {

                  'child-component': {

                  template: "<div>Editing? {{isEditing}}</div>",
                  props: {

                  isEditing: {

                  required: true,
                  type: Boolean
                  }
                  }
                  }
                  },
                  data(){

                  return {

                  editMode: true,
                  schema: {

                  disabled: false
                  }
                  }
                  },
                  methods: {

                  change(){

                  this.editMode = !this.editMode;
                  }
                  },
                  watch: {

                  editMode(n){

                  this.schema.disabled = !n;
                  }
                  }
                  }
                  </script>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 8 at 12:24

























                  answered Nov 8 at 11:28









                  Bruno Simão

                  468




                  468
























                      up vote
                      0
                      down vote













                      Thanks for your response! I think I havent described my problem enough. I understood that a variable isnt referencable only the objects. I post the answer I got in the Vue forum, in the hope I can help someone else, because this solved my problem. Solution



                      <template>
                      <form-generator :schema="schema">
                      </template>

                      <script>
                      Data() {
                      return {
                      EditMode: false,
                      },
                      methods: {
                      Edit() {
                      this.EditMode = true.
                      }
                      },
                      computed: {
                      schema() {
                      return [
                      {
                      type: "MInput",
                      disabled: !this.EditMode,
                      }
                      ]
                      }
                      },
                      </script>





                      share|improve this answer










                      New contributor




                      Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






















                        up vote
                        0
                        down vote













                        Thanks for your response! I think I havent described my problem enough. I understood that a variable isnt referencable only the objects. I post the answer I got in the Vue forum, in the hope I can help someone else, because this solved my problem. Solution



                        <template>
                        <form-generator :schema="schema">
                        </template>

                        <script>
                        Data() {
                        return {
                        EditMode: false,
                        },
                        methods: {
                        Edit() {
                        this.EditMode = true.
                        }
                        },
                        computed: {
                        schema() {
                        return [
                        {
                        type: "MInput",
                        disabled: !this.EditMode,
                        }
                        ]
                        }
                        },
                        </script>





                        share|improve this answer










                        New contributor




                        Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.




















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Thanks for your response! I think I havent described my problem enough. I understood that a variable isnt referencable only the objects. I post the answer I got in the Vue forum, in the hope I can help someone else, because this solved my problem. Solution



                          <template>
                          <form-generator :schema="schema">
                          </template>

                          <script>
                          Data() {
                          return {
                          EditMode: false,
                          },
                          methods: {
                          Edit() {
                          this.EditMode = true.
                          }
                          },
                          computed: {
                          schema() {
                          return [
                          {
                          type: "MInput",
                          disabled: !this.EditMode,
                          }
                          ]
                          }
                          },
                          </script>





                          share|improve this answer










                          New contributor




                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          Thanks for your response! I think I havent described my problem enough. I understood that a variable isnt referencable only the objects. I post the answer I got in the Vue forum, in the hope I can help someone else, because this solved my problem. Solution



                          <template>
                          <form-generator :schema="schema">
                          </template>

                          <script>
                          Data() {
                          return {
                          EditMode: false,
                          },
                          methods: {
                          Edit() {
                          this.EditMode = true.
                          }
                          },
                          computed: {
                          schema() {
                          return [
                          {
                          type: "MInput",
                          disabled: !this.EditMode,
                          }
                          ]
                          }
                          },
                          </script>






                          share|improve this answer










                          New contributor




                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited Nov 8 at 13:31





















                          New contributor




                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered Nov 8 at 13:25









                          Itpalert

                          11




                          11




                          New contributor




                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Itpalert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






















                              Itpalert is a new contributor. Be nice, and check out our Code of Conduct.










                               

                              draft saved


                              draft discarded


















                              Itpalert is a new contributor. Be nice, and check out our Code of Conduct.













                              Itpalert is a new contributor. Be nice, and check out our Code of Conduct.












                              Itpalert is a new contributor. Be nice, and check out our Code of Conduct.















                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204805%2freactivity-in-depth-in-data%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest




















































































                              Popular posts from this blog

                              How to pass form data using jquery Ajax to insert data in database?

                              National Museum of Racing and Hall of Fame

                              Guess what letter conforming each word