zoukankan      html  css  js  c++  java
  • Vue.js小demo

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="./vue.js"></script>
    </head>
    <body>
        <div id="root">
            <!-- <input type="text" v-model="msg">
            <button @click="handleClick">submit</button>
            <ul>
                <li v-for="(item, index) in items" :key="index">{{item}}<span @click="deleteClick(index)">delete</span></li>
            </ul> -->
        </div>
        <script>
    Vue.component("item-list", {
        template: `
            <li>{{itemprops}}<span @click="handleDeleteSon(index)">delete</span></li>
            `,
        props: ["itemprops", "index"],
        methods: {
            handleDeleteSon(index) {
                this.$emit("handleDeleteS", index);
            }
        }
    });
    
    var app = new Vue({
        el: "#root",
        data: {
            msg: '',
            items: []
        },
        template: `
            <div>
                <input type="text" v-model="msg">
                <button @click="handleClick">submit</button>
                <ul>
                <item-list v-for="(item, index) in items" :key="index" :itemprops="item" :index="index" @handleDeleteS="deleteClick"></item-list>
                </ul>
            </div>
            `,
        methods: {
            handleClick() {
                this.items.push(this.msg);
                this.msg = '';
            },
            deleteClick(index) {
                this.items.splice(index, 1);
            }
        }
    });
        </script>
    </body>
    </html>
    
  • 相关阅读:
    软工人日常
    11.5
    11.4
    11.3
    11.2阅读笔记
    11.1阅读笔记
    10.31 异常
    10.30动手动脑
    10.29
    10.28
  • 原文地址:https://www.cnblogs.com/intelwisd/p/9185474.html
Copyright © 2011-2022 走看看