Home.vue
<template>
<div class="home">
<TodoList />
</div>
</template>
<script>
import TodoList from './components/TodoList.vue'
import '@/assets/style.css';
export default {
name: 'Home',
components: {
TodoList,
},
};
</script>
TodoList.vue
<template>
<div>
<div class="input-part">
<input v-model='words' type="text">
<button v-on:click="insertItem">插入</button>
</div>
<ul>
<li v-for="(item, index) in list" v-bind:key="index">
<p>{
{
item }}</p>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'TodoList',
data() {
return {
words:'',
list: [],
};
},
methods: {
insertItem() {
this.list.push(this.words);
},
},
};
</script>
style.css
.home ul{
margin: 0;
padding: 0;
list-style-type: none;
}
.home ul li .item p span {
padding: 0 20px;
}
.home ul li .item p span:nth-child(1) {
color: blue;
}
.home ul li .item p span:nth-child(2) {
color: palevioletred;
}
main.js
这个代码感觉有问题,缺了后面的
import {
createApp } from 'vue'
import Home from './Home.vue'
createApp(Home).mount('#home')
const xxx样的没有。