ฉันกำลังพยายามตั้งค่าปุ่มนั่นเปลี่ยนแปลงข้อมูลค่าอยู่ใน Vue แต่ก็ยังมีมันตั้งค่าการใช้ localStorage initally. ด้วยวิธีนี้คุณสามารถมีมันเก็บของรัฐก่อนหน้านี้มันอยู่ในก่อนหน้าการปรับปรุงใหม่. ด้านล่างนี้เป็นรหัสฉันใช้แล้วฉันสามารถทำให้มันใช้ได้แต่รู้ว่ามันจะเป็น preferable ต้องใช้ส่วนที่คำนวณแล้วส่วนแต่ไม่สามารถเอามันต้องทำงานอย่างเหมาะสม
ใครจะรู้ว่ามันเกิดอะไรผิดเหรอ?
ของปุ่มคือกระตุ้นโดยใช้ทดสอบวิธีการและตัวแปรในคำถามคือ isGrid.
export default {
data() {
return {
option: 'default',
}
},
components: {
FileUploader,
},
mixins: [
visibilitiesMixin,
settingsMixin
],
props: {
vehicleId: {
type: Number,
required: true,
default: null,
}
},
computed: {
...mapState([
'isLoading',
'images',
'fallbackImageChecks',
'selectedImages'
]),
isGrid: {
get() {
return localStorage.getItem('isGrid');
},
},
imagesVModel: {
get() {
return this.images;
},
set(images) {
this.setImages(images);
}
},
selectedImagesVModel: {
get() {
return this.selectedImages;
},
set(images) {
this.setSelectedImages(images);
}
},
removeBgEnabled() {
return this.setting('nexus_integration_removebg_enabled') === 'enabled';
},
},
mounted() {
this.loadImages(this.vehicleId);
},
methods: {
testing() {
if (this.isGrid === 'false' || this.isGrid === false) {
localStorage.setItem('isGrid', true);
this.isGrid = true;
console.log(this.isGrid);
console.log(localStorage.getItem('isGrid'));
} else {
localStorage.setItem('isGrid', false);
this.isGrid = false;
console.log('b');
console.log(this.isGrid);
console.log(localStorage.getItem('isGrid'));
}
},
}