practice using simple vuex to pass values
store.js:
const store = new Vuex.Store({
//
state: {
headImg: ""
},
mutations:{
newImg(state,msg){
state.headImg=msg;
}
}
})
pass value: this.$store.commit ("newImg", val.HeadImgUrl);
receive:
<template>
<div>
<img :src="msg" alt="">
</div>
</template>
<script>
export default {
name: "detail",
data () {
return {
msg: ""
}
},
created(){
this.msg=this.imgSrc;
},
computed: {
imgSrc () {
return this.$store.state.headImg; //vuex
}
}
</script>
the problem is that this value is gone when the page is refreshed. How can it still exist after refreshing the page? (not long after learning vue, please give me some advice)