【vue-8】记事本案例

  • 小知识点:

列表末尾插入数据:

list.push("lihua")

列表删除数据:

# index要删除数据的索引值,1为删除数据长度
list.splice(index,1)
  • 完整示例代码:
<!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">
        <input type="text" v-model="web.name"> <button @click="add">增加</button>
        <ul>
            <li v-for="(value, index) in web.name_list">
                {{value}} <button @click="del(index)">删除</button>
            </li>           
        </ul>
        {{web.name_list.length}} <button @click="clear">清除</button>
    </div>
    <script type="module">
        import {createApp, reactive} from './vue.esm-browser.js'
        // const {createApp, reactive} = Vue
        createApp({
            // setup选项,用于设置响应式数据和方法等
            setup(){ 
                const web = reactive({
                    name:"liuhua",
                    name_list:["zhangsan", "lisi"]
                })
                const add = () =>{
                    web.name_list.push(web.name)
                }
                const del = (index) =>{
                    web.name_list.splice(index,1)
                }
                const clear = () =>{
                    web.name_list = []
                }
                return{
                    web,
                    add,
                    del,
                    clear
                }
            }
        }).mount("#app")
        // mount为挂载
    </script>
</body>
</html>

相关推荐

  1. vue黑马案例之小黑记事本组件版(含素材)

    2024-06-13 11:16:01       39 阅读
  2. vue记事本渲染以及交互

    2024-06-13 11:16:01       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-13 11:16:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-13 11:16:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-13 11:16:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-13 11:16:01       18 阅读

热门阅读

  1. SQL调优方案

    2024-06-13 11:16:01       4 阅读
  2. python中的数据分析(juypter)

    2024-06-13 11:16:01       7 阅读
  3. MySQL----索引

    2024-06-13 11:16:01       5 阅读
  4. MPLS工作过程

    2024-06-13 11:16:01       6 阅读
  5. 力扣刷题记录: 1339. 分裂二叉树的最大乘积

    2024-06-13 11:16:01       12 阅读
  6. Oracle数据库-重点信息查询方法

    2024-06-13 11:16:01       5 阅读
  7. 【前端】vue在线编辑器

    2024-06-13 11:16:01       12 阅读
  8. 北京汽车美容元宇宙,未来已来

    2024-06-13 11:16:01       10 阅读
  9. C#A类调用B类的方法,在方法中更新B类的控件

    2024-06-13 11:16:01       9 阅读
  10. 注解 - @RequestPart

    2024-06-13 11:16:01       7 阅读