Currently, I am in the process of developing a web application using vuejs 2.0. In order to create a straightforward select input, I employed the following code:
<select v-model="age">
<option value="" disabled selected hidden>Select Age</option>
<option value="1"> 1 Year</option>
<option value="11"> 11 Year</option>
</select>
In addition, within the data
section of my Vue component, I have defined:
data () {
return {
age: "",
}
},
watch: {
age: function (newAge) {
console.log("log here")
}
Nevertheless, I encountered an error message upon setting a default value for the select element:
ERROR in ./~/vue-loader/lib/template-compiler.js?id=data-v-5cf0d7e0!./~/vue-loader/lib/selector.js?type=template&index=0!./src/components/cde.vue template syntax error : inline selected attributes on will be ignored when using v-model. Declare initial values in the component's data option instead.
@ ./src/components/cde.vue 10:23-151
@ ./~/babel-loader!./~/vue-loader/lib/selector.js? type=script&index=0!./src/views/abcView.vue @ ./src/views/abcView.vue
@ ./src/router/index.js
@ ./src/app.js
@ ./src/client-entry.js
@ multi app
I attempted assigning a default value within the data section of the component, but it did not yield the desired outcome. Furthermore, I experimented with v-bind
, only to find that it caused the watchers to cease functioning properly for the 'age' variable.