Vue技巧小结(持续更新)

1. 动态生成的input自动focus

背景:

input元素在需要时才插入DOM,这时元素用autofocus属性第一次是可以获取焦点,但是如果有第二个,就不再生效,所以得另外的办法。

方法:

//在input插入DOM后,这样才能focus到。
setTimeout(function(){   inputElem.focus(); }, 0); //技巧

 2. plupload插件引入时报“mOxie undefined”

背景:

vue引入plupload插件(plupload.full.min.js)报上面的错,这个是因为这个文件依赖mOxie对象,而mOxie对象没有正常export出来。

//export代码
(function(exports) { "use strict"; var o = {}, inArray = exports.moxie.core.utils.Basic.inArray; // directly add some public classes (function addAlias(ns) { var name, itemType; for (name in ns) { itemType = typeof(ns[name]); if (itemType === 'object' && !~inArray(name, ['Exceptions', 'Env', 'Mime'])) { addAlias(ns[name]); } else if (itemType === 'function') { o[name] = ns[name]; } } })(exports.moxie); // add some manually o.Env = exports.moxie.core.utils.Env; o.Mime = exports.moxie.core.utils.Mime; o.Exceptions = exports.moxie.core.Exceptions; // expose globally exports.mOxie = o; if (!exports.o) { exports.o = o; } return o; })(this);

这里的this在vue require已经不是window, 所以才没有正常暴露出来了。

方法:

(function(){
    //用这个包裹一下,就正常了。
}).call(window);
posted @ 2017-08-02 15:14  海角在眼前  阅读(621)  评论(0编辑  收藏  举报