這篇文章主要講解了vue組件中的TagsInput,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
簡介
TagsInput
是一種可編輯的輸入框,通過回車或者分號來分割每個標(biāo)簽,用回退鍵刪除上一個標(biāo)簽。用 vue
來實現(xiàn)還是比較簡單的。
先看效果圖,下面會一步一步實現(xiàn)他。
注:以下代碼需要vue-cli環(huán)境才能執(zhí)行
(一)偽造一個輸入框
因為單行的文本框只能展示純文本,所以圖里面的標(biāo)簽實際上都是 html元素
,用vue模板來寫的話,是這樣的:
<template> <div class="muli-tags" @click='focus'> <button class='btn' v-for='(tag, index) in tags' :key='index'> {{tag}} </button> <input type="text" ref='input' v-model='current'> </div> </template> <script> export default { name: 'TagsInput', methods: { focus () { this.$refs.input.focus() }, }, data () { return { tags: [], current: '' } } } </script> <style lang='less'> .muli-tags{ padding: 5px 10px; display: block; border: 1px solid #ccc; input{ background: transparent; } } .btn{ margin: 0 5px 3px 0; padding: 4px 5px; background: #fff; border: 1px solid #eee; box-shadow: 0 0 4px; } </style>
當(dāng)前題目:vue組件中的TagsInput-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://chinadenli.net/article38/ephpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、ChatGPT、App開發(fā)、標(biāo)簽優(yōu)化、用戶體驗、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)