Vue 传参封装
1.全局引入
Vue.mixin({ methods: { setData: function (obj, callback) { let that = this let keys = [] let val, data Object.keys(obj).forEach(function (key) { keys = key.split('.') val = obj[key] data = that.$data keys.forEach(function (key2, index) { if (index + 1 == keys.length) { that.$set(data, key2, val) } else { if (!data[key2]) { that.$set(data, key2, {}) } } data = data[key2] }) }) callback && callback() } } })
2.使用示例
作者:微微一笑绝绝子
出处:https://www.cnblogs.com/wwyxjjz/p/15849093.html
本博客文章均为作者原创,转载请注明作者和原文链接。