<view class="zd_menu">
<view class="zd_menu_list" id="zdmenulist" ref="zdmenulist">
<view :id="`menuid${item.menuno}`" class="zd_menu_item" v-for="(item,index) in menuList"
:key="item.menuno" @click="changeMenu($event, item.menuno)">
<text class="zd_menu_item_text"
:style="[{color: menuindex == item.menuno ? '#13227a' : '#333333'}]">{{item.text}}</text>
<view v-if="menuindex == item.menuno" class="zd_menu_item_border_on"></view>
<view v-else class="zd_menu_item_border"></view>
</view>
</view>
<view class="zd_menu_btn" @click="openmenulist('left')">
<uni-icons type="more-filled" size="25"></uni-icons>
</view>
</view>
上面是页面的代码
下面是调用方法的代码
changeMenu(e, no) {
// console.log(e)
this.menuindex = no
let itemx = e.detail.x
console.log('1------')
let scrollContainer = document.getElementById('zdmenulist')
console.log('2------')
let middlescreenwidth = this.screenWidth / 2
// console.log('itemx:', itemx, '-middlescreenwidth:', middlescreenwidth)
console.log('3------')
let menuone = document.getElementById(`menuid${no}`)
console.log('4------')
let leftdistance = scrollContainer.scrollLeft
// console.log('leftdistance:', leftdistance)
let movedistance = middlescreenwidth - itemx
[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'getElementById' of undefined"
(found at pages/index/index.vue:1)
这种报错怎么处理呢
就这样吧001 (作者)
我试试,我主要是想知道这种document的写法不支持吗 如果不支持的话,以后我就不这么写东西了
2023-12-11 14:15