Why the data of the component cannot use the value in state in vuex, and what should I do if I want to use it?

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.

The value of computed cannot be taken in

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


you can just take out the state value in created and assign it to data


https://codeshelper.com/q/10.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c288d2-33902.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c288d2-33902.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?