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.
javascript vue.js
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.
add a comment |
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.
javascript vue.js
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.
add a comment |
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.
javascript vue.js
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
javascript vue.js
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.
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.
add a comment |
add a comment |
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>
add a comment |
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>
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.
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
edited Nov 8 at 12:24
answered Nov 8 at 11:28
Bruno Simão
468
468
add a comment |
add a comment |
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>
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.
add a comment |
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>
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.
add a comment |
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>
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>
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.
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.
add a comment |
add a comment |
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.
Itpalert is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password