other
mip provides some functions to solve various problems encountered in components and improve development efficiency.
prerenderElement
Render mip elements in advance.
If the element is not within the viewport, force the element's viewportCallback firstInviewCallback method to be triggered.
var element = document.getElementById('mip-test'); MIP.prerenderElement(element);
event-action
Additional JS code is not allowed due to mip. Therefore, a set of event action mechanisms are provided, which can trigger custom events of a certain mip element through the dom attribute.
html:
<mip-test id="test"></mip-test> <div on="tap:test.custom_event">不带参数</div> <div on="tap:test.custom_event(test_button)">带参数</div> <div on="tap:test.custom_event(test_button) tap:test.custom_event(test_button1)">多个事件</div>
JS:
// mip-test.js define(function (require) { var customEle = require('customElement').create(); customEle.prototype.build = function () { // 绑定事件,其它元素可通过 on="xxx" 触发 this.addEventAction("custom_event", function (event/* 对应的事件对象 */, str /* 事件参数 */) { console.log(str); // undefined or 'test_button' or 'test_button1' }); }; return customEle; });