vuejs2 - Using v-model with a prop on VUE.JS -


i'm trying use data coming prop v-model, following code works, warning.

<template> <div>        <b-form-input v-model="value" @change="postpost()"></b-form-input> </div> </template> <script>     import axios 'axios';     export default {         props: {             value: string         },         methods: {             postpost() {                 axios.put('/trajectory/inclination', {                     body: this.value                 })                     .then(response => {                     })                     .catch(e => {                         this.errors.push(e)                     })             }         }     } </script> 

the warning says:

"avoid mutating prop directly since value overwritten whenever parent component re-renders. instead, use data or computed property based on prop's value. prop being mutated: "value"

so changed , i'm using data warning says.

<template> <div>        <b-form-input v-model="_value" @change="postpost()"></b-form-input> </div> </template> <script>     import axios 'axios';      export default {         props: {             value: string         },         data() {             return {                 _value: this.value             }         },         methods: {             postpost() {                 axios.put('/trajectory/inclination', {                     body: this._value                 })                     .then(response => {                     })                     .catch(e => {                         this.errors.push(e)                     })             }         }     } 

so code it's not working , warning says:

"property or method "_value" not defined on instance referenced during render. make sure declare reactive data properties in data option"

any idea how fix first code suppress warning? (or idea on how fix second code?)

obs.: b-form-input it's not componente, textual input boostrap-vue (doc b-form-input)

bert addresses direct issue, think should know approach bit off. since sending new value postpost, don't need modify local copy. use event object sent change handler current value input.

instead of v-model, use :value, , don't include invocation parentheses when specifying change handler.

<template> <div>        <b-form-input :value="value" @change="postpost"></b-form-input> </div> </template> <script>     import axios 'axios';     export default {         props: {             value: string         },         methods: {             postpost(event) {                 axios.put('/trajectory/inclination', {                     body: event.target.value                 })                     .then(response => {                     })                     .catch(e => {                         this.errors.push(e)                     })             }         }     } </script> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -