当前位置: 首页 > news >正文

021——VUE中变异方法 push/unshift pop/shift

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>变异方法:push/unshift pop/shift</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="hdcms">
    <li v-for="v in comments">
        {{v.content}}
    </li>
    <textarea v-model="current_content" cols="30" rows="10"></textarea><br>
    <button v-on:click="push('end')">发表到最后</button>
    <button v-on:click="push('prev')">发表到前面</button>
    <br>
    <button v-on:click="del('pop')">删除最后一条</button>
    <button v-on:click="del('shift')">删除第一条</button>
</div>
<script>
    var app = new Vue({
        el: '#hdcms',
        data: {
            //当前用户输入内容:
            current_content: "",
            comments: [
                {content: "后盾人"},
                {content: "老师"}
            ]
        },
        methods: {
            push(type) {
                var content = {content: this.current_content};
                switch (type) {
                    case 'end':
                        this.comments.push(content);
                        break;
                    case 'prev':
                        this.comments.unshift(content);
                        break;
                }
                this.current_content = "";
            },
            del(type) {
                switch (type) {
                    case 'pop':
                        this.comments.pop();
                        break;
                    case 'shift':
                        this.comments.shift();
                        break;
                }
            }
        }
    });
</script>

</body>
</html>

  

转载于:https://www.cnblogs.com/yiweiyihang/p/8107804.html

相关文章:

  • P1197 [JSOI2008]星球大战(并查集判断连通块+正难则反)
  • 泛型的继承和通配符,同时归纳集合部分的面试点
  • VS 之 InstallShield Limited Edition for Visual Studio 2015 图文教程
  • utf
  • shell 并发进程的例子
  • 新手练练----也做即时通信系统(1)
  • 2017双11技术揭秘—分布式缓存服务Tair的热点数据散列机制
  • 8.不绑定(ngNonBindable)
  • spring boot 2.0之使用spring boot
  • ELK实战之Tomcat的json日志收集
  • 爬虫如何解决验证码的问题
  • PostgreSQL 时序数据案例 - 时间流逝, 自动压缩, 同比\环比
  • 使用 HttpClient 4 进行文件上传
  • 深入解析Spring Cloud内置的Zuul过滤器
  • exe4j打包jar文件成exe .
  • [deviceone开发]-do_Webview的基本示例
  • angular2 简述
  • Java|序列化异常StreamCorruptedException的解决方法
  • JavaScript服务器推送技术之 WebSocket
  • js面向对象
  • MySQL数据库运维之数据恢复
  • Swift 中的尾递归和蹦床
  • vue 配置sass、scss全局变量
  • Vue2 SSR 的优化之旅
  • 复习Javascript专题(四):js中的深浅拷贝
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 浅谈Golang中select的用法
  • 使用权重正则化较少模型过拟合
  • 因为阿里,他们成了“杭漂”
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • #Linux杂记--将Python3的源码编译为.so文件方法与Linux环境下的交叉编译方法
  • (+3)1.3敏捷宣言与敏捷过程的特点
  • (16)UiBot:智能化软件机器人(以头歌抓取课程数据为例)
  • (多级缓存)多级缓存
  • (分享)一个图片添加水印的小demo的页面,可自定义样式
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (附源码)计算机毕业设计高校学生选课系统
  • (十六)Flask之蓝图
  • (已解决)报错:Could not load the Qt platform plugin “xcb“
  • (转)Oracle 9i 数据库设计指引全集(1)
  • . Flume面试题
  • .apk文件,IIS不支持下载解决
  • .Net - 类的介绍
  • .net 打包工具_pyinstaller打包的exe太大?你需要站在巨人的肩膀上-VC++才是王道
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • .net反编译工具
  • .Net小白的大学四年,内含面经
  • .NET学习全景图
  • @Query中countQuery的介绍
  • [ CTF ]【天格】战队WriteUp- 2022年第三届“网鼎杯”网络安全大赛(青龙组)
  • [ web基础篇 ] Burp Suite 爆破 Basic 认证密码
  • [AIGC] Redis基础命令集详细介绍
  • [BZOJ2208][Jsoi2010]连通数
  • [C++][数据结构][算法]单链式结构的深拷贝
  • [CF703D]Mishka and Interesting sum/[BZOJ5476]位运算