【发布时间】:2021-12-15 15:57:30
【问题描述】:
我在Vue3/Laravel8 app 中使用Laravel Nova 构建了一个原始Content Management System。作为菜鸟,我使用axios.get 从database 获取图像链接和降价,并将其分配给reactive state,如下所示:
<script setup>
import {reactive} from 'vue';
import DOMPurify from "dompurify";
import marked from "marked";
const state = reactive({
locale: sessionStorage.locale,
content: "",
image: ""
})
axios.get('/home')
.then(res => {
const data = res.data[0]
state.content = DOMPurify.sanitize(marked(data['content_' + state.locale]))
state.image = 'storage/' + data['image']
})
.catch(err => {
console.log(err);
console.log(err.response);
});
</script>
并在我的模板中渲染image/markdown:
<template>
<section id="home" class="home">
<div class="home-image" :style="{'background-image': 'url(' + state.image + ')'}"></div>
<div v-html="state.content"></div>
</section>
</template>
这会产生两个问题:
- 每次刷新或加载页面时,应用程序都必须等待
response。 - 每次刷新或加载页面时都会呈现
images/content。
有没有办法缓存response data?我只需要存储string information。
我已尝试使用 sessionStorage 执行此操作,但在初始页面加载期间它不适用于 state = reactive()(或者有办法吗?)。
【问题讨论】:
标签: laravel vue.js axios vuejs3 laravel-nova