In the small program which is not dom elements of this program will be smaller as long as we should know, but in peacetime development, we occasionally encounter situations need to click on an element gets its value, here to give you two lists case solution
Method 1: Data Binding
This is the case, the corresponding scene is the case of only one button or element calls this method
.vue data in your data file which adds variable
Data () { return { MSG: 'Su-Su Hey Hey Hey Su' };
getData(){ console.log( this.msg ) }
Button
<button @click="getData()" name="bu">{{msg}}</button>
But for multiple elements call this method, then this is impractical in this way, the second method below is the way to make up for a lack of
Second way
data .vue file defines a variable to receive
data() { return { concat:'12345678' };
In the template, the custom attribute data-text
< Van-Cell-Group > < Van Cell- title = "phone" value = "click to call" Data-text = "*******" icon = "Phone" /> < Van Cell- title = "micro-Letter " value =" click to copy " the Data-text =" ******** " icon =" Chat " @click =" copy ($ Event) " /> < Van-the Cell title =" E-mail " value =" click copy " the Data-text =" ******* " @click =" copy ($ Event) " icon="invition"/> <van-cell title="博客" value="点击复制" data-text="****** " icon="desktop-o" @click="copy($event)"/> </van-cell-group>
When the function references must remember that the incoming $ Event , otherwise, access to e will be an undefined
Defined Functions
copy(e){ var that = this; console.log(e.currentTarget.dataset.text) wx.setClipboardData({ data: e.currentTarget.dataset.text, success: function (res) { wx.showModal({ title: '提示', content: '复制成功', success: function (res) { if (res.confirm) { console.log('确定') } else if (res.cancel) { console.log('取消') } } }) } });