methods.js 851 B

123456789101112131415161718192021222324252627282930313233
  1. import Vue from 'vue';
  2. import _ from 'lodash';
  3. const Plugin = {
  4. install(Vue, options) {
  5. // 3. 注入组件
  6. Vue.mixin({
  7. created() {
  8. if (this.$store && !this.$store.$toUndefined) {
  9. this.$store.$toUndefined = this.$toUndefined;
  10. }
  11. },
  12. });
  13. // 4. 添加实例方法
  14. Vue.prototype.$toUndefined = object => {
  15. let keys = Object.keys(object);
  16. keys.map(item => {
  17. object[item] = object[item] === '' ? (object[item] = undefined) : object[item];
  18. });
  19. return object;
  20. };
  21. Vue.prototype.$turnTo = item => {
  22. if (item.info_type == 1) {
  23. window.open(item.url);
  24. } else {
  25. let router = window.vm.$router;
  26. let route = window.vm.$route.path;
  27. router.push({ path: `/info/detail?id=${item.id}` });
  28. }
  29. };
  30. },
  31. };
  32. Vue.use(Plugin);