5***@qq.com
5***@qq.com
  • 发布:2016-12-20 15:54
  • 更新:2019-01-24 16:35
  • 阅读:4987

vue单组件使用mui下拉刷新,切换路由后下拉事件失效

分类:MUI

<template>
<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
<div class="mui-scroll">
<p>pullRefresh</p>
</div>
</div>
</template>
<script>
export default {
created:function() {
console.log('created');
mui.init({
pullRefresh: {
container: '#pullrefresh',
down: {
callback: this.pulldownRefresh
},
up: {
contentrefresh: '正在加载...',
callback: this.pullupRefresh
}
}
});
},
ready: function() {
// mui.init({
// pullRefresh: {
// container: '#pullrefresh',
// down: {
// callback: this.pulldownRefresh
// },
// up: {
// contentrefresh: '正在加载...',
// callback: this.pullupRefresh
// }
// }
// });
},
methods: {
pulldownRefresh() {
console.log('pulldownRefresh');
mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
},
pullupRefresh() {
console.log('pullupRefresh');
mui('#pullrefresh').pullRefresh().endPullupToRefresh();
}
}
}
</script>

每次切换路由console.log('created'); 都能正常输出内容,但是Mui.init() 好像不能重复执行?

2016-12-20 15:54 1 条评论 负责人:无 分享
已邀请:
yunqifeiyang

yunqifeiyang

源码中有一段```javascript
/**

  • 单页配置 初始化
  • @param {object} options
    */
    $.init = function(options) {

    $.options = $.extend(true, $.global, options || {});  
    $.ready(function() {  
        $.doAction('inits', function(index, init) {  
            var isInit = !!(!inits[init.name] || init.repeat);  
            if (isInit) {  
                init.handle.call($);  
                inits[init.name] = true;  
            }  
        });  
    });  
    return this;  

    };

    因此你需要在你的created内每次调用mui.init前 加入代码:```javascript  
    for(var i = mui.hooks.inits.length-1,item;i>=0;i--){  
          item=mui.hooks.inits[i];  
          if(item.name=="pullrefresh"){  
              item.repeat=true;  
          }  
      }
  • 4***@qq.com

    这个有效,厉害!

    2018-08-23 16:12

流浪的风

流浪的风

棒棒哒

该问题目前已经被锁定, 无法添加新回复