Initialization with better-scroll in vue is successful, but there is no response.

paste the structure code: hasVerticalScroll has a value for true,scrollerHeight, if I set overflow-y:auto; for class menu-wrapper and foods-wrapper The style is also completely fine, and the print better-scroll initialization is also fine.
add: I found a strange problem. No matter whether it is a vuex call or a re-call, no matter at any stage of the life cycle to execute the calling function this.initScroll (), print, it is also given to me undfined.mounted ().

1.HTML:

<div class="goods">
    <!-- , -->
    <div class="menu-wrapper" ref="menuScroll">
      <ul>
        <li class="menu-item"></li>
      </ul>
    </div>
    <!-- , -->
    <div class="foods-wrapper" ref="foodScroll">
      <ul>
        <!--  -->
        <li class="container-list"></li>
        <!--  -->
        <li class="food-list" v-for="(item,index) in setGoods" :key="index">
          <h3 class="title">{{item.name}}</h3>
          <!--  -->
          <ul>
            <li class="food-item"></li>
          </ul>
        </li>
      </ul>
     
    </div>
<div class="goods">

2.CSS structure code, Sass: used

.goods{
    display: flex;
    position: absolute;
    top: 190px;
    bottom: 51px;
    overflow: hidden;
    width: 100%;
    
    // 
    .menu-wrapper{
      flex: 0 0 85px;
      background: -sharpF4F4F4;
      // overflow-y: auto;
      .menu-item{
        padding: 19px 23px 9px 10px;
        border-bottom: 1px solid -sharpE4E4E4;
        position: relative;
      }
     }
     
     // 
    .foods-wrapper{
      flex: 1;
      .container-list{
        padding: 11px 11px 0 11px;
        border-bottom: 1px solid -sharpE4E4E4;
      }
      .food-list{
        padding: 11px;
        .title{
          height: 13px;
          font-size: 13px;
          background: url("../../assets/btn_yellow_highlighted@2x.png") no-repeat left center;
          background-size: 2px 10px;
          padding-left: 7px;
          margin-bottom: 12px;
        }
        .food-item{
          display: flex;
          margin-bottom: 25px;
          position: relative;
        }
      }
      
     }
     
 

3.JS Code:

<script>
  import BScroll from "better-scroll"
  
  export default {
   name: "goods",
   data() {
    return {        
     seteContainers: {},
     setGoods: [],
    }
   },
   methods: {
    initScroll (){  //
     new this.BScroll(this.$refs.menuScroll)
     new this.BScroll(this.$refs.foodScroll)
    }
   },
   created (){
    this.http.get("/api/goos").then(response => {
     if(response.data.code == 0){
      this.seteContainers = response.data.data.container_operation_source;
      this.setGoods = response.data.data.food_spu_tags;
       //
       this.initScroll()
     }
    })
   }        
  }
</script>
    

4. Printed new this.BScroll (this.$refs.menuScroll):

Mar.21,2021

attach the link https://blog.csdn.net/qq_4020. this demo is put into the project to try


you can try this.nextTick (function () {this.initScroll ()} in the request callback try


Thank you. I found the problem. In the code, the seteContainer () and setGood () data functions are not called, but the data is obtained because the computed () calculation attribute hook function has its own listening function, and it finds that the data changes are called automatically, and it has some special characteristics. If the data is put in it, other hook functions cannot be controlled, so there are the following problems: no matter at which stage initScroll () is called or asynchronously called, it is unified to undfind,. Then the scrolling plug-in is not executed even if it is initialized successfully, and I still don't have a deep understanding when I just learned vue. Thank you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31ea9-2bdb8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31ea9-2bdb8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?