3 changed files with 40 additions and 11 deletions
@ -1,16 +1,22 @@ |
|||
import { reactive } from "vue" |
|||
|
|||
interface IFile{ |
|||
filename: "", |
|||
code: "" |
|||
filename: string, |
|||
code: string |
|||
} |
|||
|
|||
interface IData{ |
|||
filelist: IFile[] |
|||
state: { |
|||
filelist: IFile[] |
|||
} |
|||
} |
|||
|
|||
const data = reactive<IData>({ |
|||
filelist: [] |
|||
state: { |
|||
filelist: [] |
|||
} |
|||
}) |
|||
|
|||
export default data |
|||
export default function useState(){ |
|||
return data.state |
|||
} |
@ -1,13 +1,36 @@ |
|||
<template> |
|||
<form action="/" :onSubmit="onSubmit"> |
|||
<input type="text" placeholder="请输入文件名" /> |
|||
<input type="submit" /> |
|||
</form> |
|||
<div class="files"> |
|||
{{ state.filelist }} |
|||
<form action="/" :onSubmit="onSubmit"> |
|||
<input class="input" v-model="filename" type="text" placeholder="请输入文件名" /> |
|||
<input class="submit" type="submit" value="添加" /> |
|||
</form> |
|||
</div> |
|||
</template> |
|||
|
|||
<script lang="ts" setup> |
|||
import useState from "./data" |
|||
import { ref } from "vue" |
|||
|
|||
const state = useState() |
|||
const filename = ref("") |
|||
|
|||
function onSubmit(e: Event) { |
|||
e.preventDefault() |
|||
console.log(123) |
|||
state.filelist.push({ |
|||
filename: filename.value, |
|||
code: "", |
|||
}) |
|||
filename.value = "" |
|||
} |
|||
</script> |
|||
|
|||
<style lang="less" scoped> |
|||
.input { |
|||
border: 0; |
|||
outline: 0; |
|||
font-size: 20px; |
|||
height: 50px; |
|||
line-height: 50px; |
|||
} |
|||
</style> |
|||
|
Loading…
Reference in new issue