fix: 修改图片组件不能动态更新的问题

This commit is contained in:
奔跑的面条 2022-06-26 15:35:40 +08:00
parent bf1b81e554
commit 633bf987ab
4 changed files with 41 additions and 26 deletions

View File

@ -41,7 +41,7 @@ const mockObject: MockMethod[] = [
{
url: imageUrl,
method: RequestHttpEnum.GET,
response: () => test.fetchImage,
response: () => test.fetchImage(Math.round(Math.random()*10)),
},
]

View File

@ -80,10 +80,10 @@ export default {
msg: '请求成功',
data: '@paragraph(1, 10)',
},
fetchImage: {
fetchImage: (num: number) => ({
code: 0,
status: 200,
msg: '请求成功',
data: `https://robohash.org/${Math.round(Math.random()*10)}`,
},
data: `https://robohash.org/${num}`,
}),
}

View File

@ -1,5 +1,5 @@
<template>
<collapse-item name="图片" :expanded="true">
<collapse-item name="属性" :expanded="true">
<setting-item-box name="路径" :alone="true">
<setting-item>
<n-input v-model:value="optionData.dataset" size="small"></n-input>

View File

@ -1,42 +1,57 @@
<template>
<div class="go-packages-image">
<div :style="getStyle(borderRadius)">
<n-image
:object-fit="fit"
preview-disabled
:src="dataset"
:src="option.dataset"
:fallback-src="requireErrorImg()"
:width="w"
:height="h"
></n-image>
</div>
</div>
</template>
<script setup lang="ts">
import { PropType, computed, toRefs } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { PropType, shallowReactive, watch, toRefs } from 'vue'
import { requireErrorImg } from '@/utils'
import { useChartDataFetch } from '@/hooks'
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType>,
required: true,
},
required: true
}
})
const { w, h } = toRefs(props.chartConfig.attr)
const { dataset, fit, borderRadius } = toRefs(props.chartConfig.option)
const option = shallowReactive({
dataset: ''
})
const getStyle = (radius: number) => {
return {
borderRadius: `${radius}px`,
overflow: 'hidden',
overflow: 'hidden'
}
}
</script>
<style lang="scss" scoped>
.go-packages-image {
}
</style>
//
watch(
() => props.chartConfig.option.dataset,
(newData: any) => {
option.dataset = newData
},
{
immediate: true
}
)
//
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
option.dataset = newData
})
</script>