小编给大家分享一下如何使用Vue做一个简单的todo应用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
创新互联建站咨询电话:028-86922220,为您提供成都网站建设网页设计及定制高端网站建设服务,创新互联建站网页制作领域10年,包括广告推广等多个方面拥有多年的营销推广经验,选择创新互联建站,为企业保驾护航!1. 引用vue.js
<!DOCTYPE html> <html> <head> <script src="http://vuejs.org/js/vue.js"></script> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <div id="root"> <input type="text" v-model="inputValue"> <button @click="handlerAdd">提交</button> <ul> <li v-for="(item,index) of lists" :key="index" @click="handlerDel(index)" > {{item}} </li> </ul> </div> <script> new Vue({ el: '#root', data: { inputValue: '', lists: [] }, methods: { handlerAdd: function() { this.lists.push(this.inputValue); this.inputValue = ''; }, handlerDel: function(index) { this.lists.splice(index, 1); } } }); </script> </body> </html>
2. 全局组件注册
<!DOCTYPE html> <html> <head> <script src="http://vuejs.org/js/vue.js"></script> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <div id="root"> <input type="text" v-model="inputValue"> <button @click="handlerAdd">提交</button> <ul> <todo-item v-for="(item,index) of lists" :content = "item" :index = "index" :key = "index" @delete="handlerDel" > </todo-item> </ul> </div> <script> Vue.component('todoItem', { props: { content: String, index: Number }, template: '<li @click="handlerClick">{{content}}</li>', methods: { handlerClick: function(){ this.$emit('delete', this.index); } } }); new Vue({ el: '#root', data: { inputValue: '' , lists: [] }, methods: { handlerAdd: function() { this.lists.push(this.inputValue); this.inputValue = ''; }, handlerDel: function(index) { this.lists.splice(index,1); } } }); </script> </body> </html>
3. vue-cli脚手架
// Todo.Vue <template> <div> <input type="text" v-model="inputValue"> <button @click="handlerAdd">提交</button> <ul> <todo-item v-for="(item,index) of lists" :key="index" :content="item" :index="index" @delete="handlerDel" ></todo-item> </ul> </div> </template> <script> import TodoItem from './components/todoItem' export default { data () { return { inputValue: '', lists: [] } }, methods: { handlerAdd () { this.lists.push(this.inputValue) this.inputValue = '' }, handlerDel (index) { this.lists.splice(index, 1) } }, components: { 'todo-item': TodoItem } } </script> <style> </style> // TodoItem.vue <template> <li @click="handlerClick" class="item">{{content}}</li> </template> <script> export default { props: ['content', 'index'], methods: { handlerClick () { this.$emit('delete', this.index) } } } </script> <style scoped> ul,li { list-style: none; } .item { color: blueviolet; } </style>
以上是“如何使用Vue做一个简单的todo应用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联成都网站设计公司行业资讯频道!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:如何使用Vue做一个简单的todo应用-创新互联
转载来源:https://www.cdcxhl.com/article18/dgpcgp.html
成都网站建设公司_创新互联,为您提供微信小程序、ChatGPT、App设计、品牌网站制作、网站维护、网站设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联