WeChat Mini Programs: how to use button to get the custom attribute value of view?

wxml:

<view class="index-hd" data-vid="11111111" data-uid="22222222"></view>
<button class="tijiao"  type="primary" bindtap="bindtap"></button>

js:

bindtap(e){

console.log(e.target.dataset.vid)

  }

you can't get it by clicking on it like this. You need to write data-vid into button to get


view is nested in button


if it is not < view bindtap= "" data-index= "> < button > < / button > < / view >, then use to get the element SelectorQuery.select (string selector)

Menu