Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  190] [ 3]  / answers: 1 / hits: 42359  / 8 Years ago, wed, november 2, 2016, 12:00:00

I am creating a webapp using vuejs 2.0. I have created simple select input using 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>


and I have this in data of my Vue component:



data () {
return {
age: ,
}
},
watch: {
age: function (newAge) {
console.log(log here)
}


But I start to get this error when adding default value for select:




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 tried to give default value in the data section of the component as well, but then nothing happened. I tried v-bind also but then watchers stopped working on age variable.


More From » select

 Answers
1

The only thing needed to work this was remove selected from default option:



 <select v-model=age>
<option value= disabled hidden>Select Age</option>
.....
</select>

[#60213] Saturday, October 29, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;