Vue--La bibliothèque de ZY

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h3>ZY的书架</h3>
        <ul>
            <li v-for = "(item, index) in BookList" :key="item.id">//必须设置主键!
                <span>{
   
   {item.name}} </span>
                <span>{
   
   {item.author}} </span>
                //设置点击事件
                <button @click = "del(item.id)">移出书架</button>
            </li>
        </ul>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <script>
        const vm = new Vue({
            el : '#app',
            data : {
                BookList: [
                    { id: 1, name: '《史上最强炼气期》', author: '李道然'},
                    { id: 2, name: '《我有一剑》', author: '青鸾峰上'},
                    { id: 3, name: '《一剑独尊》', author: '青鸾峰上'},
                    { id: 4, name: '《万古第一神》', author: '风青阳'},
                    { id: 5, name: '《我在昆仑闭关三百年》', author: '飞燕'}
                ]
            },
            methods: {
               del (id) {
                //保留除了参数以外的所有id
                this.BookList = this.BookList.filter(item => item.id != id)
               }
            }
        })
    </script>
</body>
</html>

Je suppose que tu aimes

Origine blog.csdn.net/m0_62600503/article/details/132381504
conseillé
Classement