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