<script lang="ts" setup> import { computed, ref } from "vue"; interface User { date: string; name: string; address: string; } const search = ref(""); const filterTableData = computed(() => tableData.filter( (data) => !search.value || data.name.toLowerCase().includes(search.value.toLowerCase()) ) ); const handleEdit = (index: number, row: User) => { console.log(index, row); }; const handleDelete = (index: number, row: User) => { console.log(index, row); }; const tableData: User[] = [ { date: "2016-05-03", name: "Tom", address: "No. 189, Grove St, Los Angeles", }, { date: "2016-05-02", name: "John", address: "No. 189, Grove St, Los Angeles", }, { date: "2016-05-04", name: "Morgan", address: "No. 189, Grove St, Los Angeles", }, { date: "2016-05-01", name: "Jessy", address: "No. 189, Grove St, Los Angeles", }, ]; </script>怎么改成JS格式
时间: 2024-02-04 07:02:44 浏览: 89
你可以将 `<script lang="ts" setup>` 修改为 `<script>`,表示使用普通的 JavaScript 语法。同时,你需要添加类型声明,例如:
```
import { computed, ref } from "vue";
const search = ref("");
const tableData = [
{
date: "2016-05-03",
name: "Tom",
address: "No. 189, Grove St, Los Angeles"
},
{
date: "2016-05-02",
name: "John",
address: "No. 189, Grove St, Los Angeles"
},
{
date: "2016-05-04",
name: "Morgan",
address: "No. 189, Grove St, Los Angeles"
},
{
date: "2016-05-01",
name: "Jessy",
address: "No. 189, Grove St, Los Angeles"
}
];
/**
* @type {import("vue").ComputedRef<User[]>}
*/
const filterTableData = computed(() =>
tableData.filter(
(data) =>
!search.value || data.name.toLowerCase().includes(search.value.toLowerCase())
)
);
/**
* @param {number} index
* @param {User} row
*/
const handleEdit = (index, row) => {
console.log(index, row);
};
/**
* @param {number} index
* @param {User} row
*/
const handleDelete = (index, row) => {
console.log(index, row);
};
```
需要注意的是,你需要自己添加类型声明,这里的 `User` 类型可以根据你的实际需求进行修改。
阅读全文