Naive script setup写法上传注意

Naive UI上传改成script setup写法

Naive UI官网写法

<template>
  <n-button
    :disabled="!fileListLength"
    style="margin-bottom: 12px"
    @click="handleClick"
  >
    上传文件
  </n-button>
  <n-upload
    ref="upload"
    action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f"
    :default-upload="false"
    multiple
    @change="handleChange"
  >
    <n-button>选择文件</n-button>
  </n-upload>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import type { UploadInst, UploadFileInfo } from 'naive-ui'

export default defineComponent({
  setup () {
    const fileListLengthRef = ref(0)
    const uploadRef = ref<UploadInst | null>(null)

    return {
      upload: uploadRef,
      fileListLength: fileListLengthRef,
      handleChange (options: { fileList: UploadFileInfo[] }) {
        fileListLengthRef.value = options.fileList.length
      },
      handleClick () {
        uploadRef.value?.submit()
      }
    }
  }
})
</script>

改成script setup写法

<template>
  <n-button
    style="margin-bottom: 12px"
    @click="handleClick"
  >
    上传文件
  </n-button>
  <n-upload
    ref="uploadRef"
    action="https://www.mocky.io/v2/5e4bafc63100007100d8b70f"
    :default-upload="false"
    multiple
    @change="handleChange"
  >
    <n-button>选择文件</n-button>
  </n-upload>
</template>

<script setup lang="ts">
import type { UploadFileInfo, UploadInst } from 'naive-ui'

const fileListLengthRef = ref(0)
const uploadRef = ref<UploadInst | null>(null)

const handleChange = (options: { fileList: UploadFileInfo[] }) => {
  fileListLengthRef.value = options.fileList.length
}
const handleClick = () => {
  uploadRef.value?.submit()
}
</script>

</script>

下边的命名要跟上边的ref的名称一致
要跟上边的ref的名称一致

<script setup lang="tsx"> import { NButton, NPopconfirm, NTag } from "naive-ui"; import { fetchGetChangeLedgerList,fetchBatchDeleteChange,fetchDeleteChange,getDeptOptions,clearDeptCache } from "@/service/api"; import { $t } from "@/locales"; import { useAppStore } from "@/store/modules/app"; import { useTable, useTableOperate } from "@/hooks/common/table"; import { useAuth } from "@/hooks/business/auth"; import LedgerOperateDrawer from "./modules/ledger-operate-drawer.vue"; import LedgerSearch from "./modules/ledger-search.vue"; import LedgerUploadDrawer from "./modules/ledger-upload-drawer.vue"; import { useBoolean } from "@sa/hooks"; import { canUpgradeRecord } from "@/constants/business"; import { ref, onMounted } from "vue"; import {useDepartment} from "@/hooks/common/useDepartment" import { exportXlsx, SheetData } from "@/utils/export-excel"; // 使用封装的部门功能 const { deptLoading, deptOptions, } = useDepartment(); const appStore = useAppStore(); const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams, } = useTable({ apiFn: fetchGetChangeLedgerList, showTotal: true, apiParams: { current: 1, size: 10, // if you want to use the searchParams in Form, you need to define the following properties, and the value is null // the value can not be undefined, otherwise the property in Form will not be reactive source: null, pecoName: null, peco: null, softwareChange: null, projectno: null, dept: null, canUpgrade: null, softResponsiblePerson: null, elecResponsiblePerson: null, changeResponsiblePerson: null, customerDemandTime: null, softCompletionTime:null, hardCompletionTime: null, fmtCustomerDemandTime:null, fmtSoftCompletionTime:null, fmtHardCompletionTime: null, }, columns: () => [ { type: "selection", align: "center", width: 48, }, { key: "index", title: $t("common.index"), align: "center", width: 64, }, { key: "hwswcoId", title: $t("page.change.ledger.hwswcoId"), align: "center", minWidth: 50, }, { key: "source", title: $t("page.change.ledger.source"), align: "center", width: 50, }, { key: "pecoName", title: $t("page.change.ledger.pecoName"), align: "center", minWidth: 50, }, { key: "peco", title: $t("page.change.ledger.peco"), align: "center", minWidth: 50, }, { key: "softwareChange", title: $t("page.change.ledger.softwareChange"), align: "center", minWidth: 150, }, { key: "projectno", title: $t("page.change.ledger.projectno"), align: "center", minWidth: 50, }, { key: "dept", title: $t("page.change.ledger.dept"), align: "center", width: 130, render: (row) => { // 使用部门选项映射部门名称 if (row.dept && deptOptions.value.length > 0) { const dept = deptOptions.value.find(option => option.value === row.dept); if (dept) { return <NTag type="info">{dept.label}</NTag>; } } return null; }, }, { key: "softResponsiblePersonName", title: $t("page.change.ledger.softResponsiblePersonName"), align: "center", minWidth: 50, }, { key: "elecResponsiblePersonName", title: $t("page.change.ledger.elecResponsiblePersonName"), align: "center", minWidth: 50, }, // { // key: "changeResponsiblePerson", // title: $t("page.change.ledger.changeResponsiblePerson"), // align: "center", // minWidth: 50, // }, { key: "canUpgrade", title: $t("page.change.ledger.canUpgrade"), align: "center", minWidth: 50, render: (row) => { if (row.canUpgrade) { console.log( row.canUpgrade, canUpgradeRecord[ row.canUpgrade as Api.Change.canUpgrade ]) const label = $t( canUpgradeRecord[ row.canUpgrade as Api.Change.canUpgrade ] ); return <NTag type="default">{label}</NTag>; } return null; }, }, { key: "fmtCustomerDemandTime", title: $t("page.change.ledger.customerDemandTime"), align: "center", minWidth: 50, }, { key: "fmtSoftCompletionTime", title: $t("page.change.ledger.softCompletionTime"), align: "center", minWidth: 50, }, { key: "fmtHardCompletionTime", title: $t("page.change.ledger.hardCompletionTime"), align: "center", minWidth: 50, }, // { // key: "fmtPlanCompletionTime", // title: $t("page.change.ledger.planCompletionTime"), // align: "center", // minWidth: 50, // }, { key: "operate", title: $t("common.operate"), align: "center", width: 130, render: (row) => ( <div class="flex-center gap-8px"> {hasAuth("B_ChangeLedger_Upgrade") ? ( <NButton type="primary" ghost size="small" onClick={() => window.open (`http://192.168.100.63/pro/hwswco-upgrade-${row.hwswcoId}.html`,"_blank")} > {$t("common.upgrade")} </NButton> ) : null} {hasAuth("B_ChangeLedger_Assign") ? ( <NButton type="primary" ghost size="small" onClick={() => window.open(`http://192.168.100.63/pro/hwswco-view-${row.hwswcoId}.html`,"_blank")} > {$t("common.assign")} </NButton> ) : null} </div> ), }, ], });onClick跳转的地址内嵌到前端
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值