替换v-model API 为 defineModel

This commit is contained in:
piexlmax(奇淼
2024-03-13 15:17:57 +08:00
parent 421304d4a3
commit e9100a9542
7 changed files with 201 additions and 208 deletions
+13 -14
View File
@@ -1,36 +1,35 @@
<template>
<vue-office-docx :src="docx" @rendered="rendered">
</vue-office-docx>
<vue-office-docx
:src="docx"
@rendered="rendered"
/>
</template>
<script>
export default {
name: "Docx"
name: 'Docx'
}
</script>
<script setup>
import {ref, watch} from 'vue'
import { ref, watch } from 'vue'
// 引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx'
// 引入相关样式
import '@vue-office/docx/lib/index.css'
const props = defineProps({
modelValue: {
type: String,
default: () => ""
}
const model = defineModel({
type: String,
})
const docx = ref(null)
watch(
() => props.modelValue,
value => docx.value = value,
{immediate: true}
() => model,
value => { docx.value = value },
{ immediate: true }
)
const rendered = () => {
}
</script>
<style lang="scss" scoped>
</style>
</style>
+3 -7
View File
@@ -33,16 +33,12 @@ import Excel from '@/components/office/excel.vue'
const path = ref(import.meta.env.VITE_BASE_API)
const props = defineProps({
modelValue: {
type: String,
default: () => ''
}
})
const model = defineModel({ type: String})
const fileUrl = ref('')
const ext = ref('')
watch(
() => props.modelValue,
() => model,
val => {
fileUrl.value = val
const fileExt = val.split('.')[1] || ''