<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
const app = Vue.createApp({
template: `
<div>
<div>
<input type="text" :value="inputValue" @input="handleInputValueChange" />
<button @click="handleClick">提交</button>
</div>
<ul>
<li v-for="(item,index) of list" :key="index">
第{{index+1}}件事是{{item}}
</li>
</ul>
</div>
`,
setup() {
const { reactive, ref } = Vue;
const list = reactive([]);
const handleInputValueChange = (e) => {
const { reactive, ref } = Vue;
inputValue.value = e.target.value;
};
const inputValue = ref("");
const handleClick = () => {
list.push(inputValue.value);
inputValue.value = "";
};
return {
list,
inputValue,
handleInputValueChange,
handleClick,
};
},
});
const vm = app.mount("#root");
</script>
</html>