I want a variable in the drop-down box v-model data, and the default value of this variable is the constant defined in state, but what if it doesn"t change with the value in state?
reference:
https://codeshelper.com/q/10.
data (), because computed depends on data
and data and computed are ready in created (), so you can assign it manually in created:
created () {
this.selectValue = this.SINGLE_GAME
}
23 minutes ago, answer 3 comments and praise the editor
SevenOutman
2.3k reputation
but this is still not intuitive, and the amount of code will increase
select=state.SINGLE_GAME ;
if you write like that, you must first declare in data
select=0;
then created
select=state.SINGLE_GAME
still doesn"t look intuitive, and the amount of code has increased
-coder94 21 minutes ago
replied to coder94:
if you have to put this constant in vuex, that"s what you have to do. If you want to be intuitive, you can put the constants in a separate file instead of in vuex.
import { SINGLE_GAME } from "./constants"
// ...
data() {
return {
selectValue: SINGLE_GAME
}
}
-SevenOutman 18 minutes ago
reply SevenOutman:
Thank you
-coder94 13 minutes ago