在本篇内容里小编给大家分享的是关于vue
本文来源gaodai.ma#com搞##代!^码@网3实现商品列表的添加删除实例讲解,有兴趣的朋友们可以参考下。
我们首先来看下代码:
<div id="app"> <div class="container"> <div class="form-group"><label for="exampleInputName2">ID:</label></div><div class="form-group"><label for="exampleInputEmail2">Name:</label></div><button class="btn btn-primary" type="button">提交</button><table class="table table-hover table-striped"> <tbody> <tr> <td>ID</td><td>品牌名称</td><td>添加时间</td><td>操作</td></tr><tr> <td>{{item.id}}</td><td>{{item.pp_name}}</td><td>{{item.add_time | getTime()}}</td><td>删除</td></tr></tbody></table></div></div>
内容补充:
vue中注册组件,实现列表的添加删除效果
1、首先在html的标签中
导入vue.js
2、在body中创建一个应用vue模板的容器
// vue起作用的区域root <div id="root"> // input与mesg数据绑定 <button>提交</button><ul> </ul></div>
3、在script标签中创建并注册名为todo-item的组件
Vue.component('todo-item', { props: ['content', 'index'], template: '<li>{{content}}</li>', methods: { handelClick: function() { //点击li元素就触发delete方法 this.$emit('delete', this.index); } } })
4、在script标签中初始化vue实例
new Vue({ el: '#root', data() { return { list: [], mesg: '' } }, methods: { //点击提交按钮,输入文本信息就加入列表 handle: function() { if(this.mesg==''){ return; } this.list.push(this.mesg); this.mesg = '' }, deletes: function(index) { alert(index) this.list.splice(index, 1); } } })
到此这篇关于vue实现商品列表的添加删除实例讲解的文章就介绍到这了,更多相关vue商品列表添加删除内容请搜索gaodaima搞代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持gaodaima搞代码网!
以上就是vue实现商品列表的添加删除实例讲解的详细内容,更多请关注gaodaima搞代码网其它相关文章!