v-html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1 v-html="title"></h1>
        <p>
            手机型号:<input type="text" v-model="newProducts.name">
            库存:<input type="number" v-model="newProducts.stock">
            <button @click="addProduct">添加</button>
        </p>
        <ul>
            <li v-for="(item,i) in products" :key="i">
                {{item.name}} 库存:{{item.stock}}
            </li>
        </ul>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            // el: "#app",

            data: {
                title: '<span style="color:red">商品管理</span>',
                newProducts: {
                  name: "",
                  stock: 0
                },
                products: [
                    {name:"iphone",stock:10},
                    {name:"huawei",stock:8}
                ]
            },
            method: {
                addProduct(){
                    this.products.push({
                        name: this.newProducts.name,
                        stock: this.newProducts.stock
                    })
                }
            }
        })
        vm.$mount("#app");
    </script>

</body>
</html>
上一篇:Redis进阶-细说分布式锁


下一篇:C++ 对象数组