hejianhao
2024-12-27 1a4aee44cb2821daa069f6279828e818699fd83d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
 
import './registerServiceWorker'
import router from './router'
import store from './store'
import axios from './utils/request';
Vue.prototype.$axios = axios
 
Vue.config.productionTip = false
Vue.use(ElementUI);
// 添加全局v-focus指令
Vue.directive("focus", {
  inserted: function (el, { modifiers: { noKeyboard } }) {
    try {
      const tagName = el.tagName;
      if (tagName !== "INPUT") {
        let child = el.children[0];
        if (child && child.tagName === "INPUT") {
          el = child;
        }
      }
      // 可以重新获得焦点又不弹起软键盘;xxx是el-input的ref
      // this.$refs[xxx].$refs.input.noKeyboardFocus(); 
      el.noKeyboardFocus = function () {
        Vue.nextTick(() => {
          this.focus();
          this.setAttribute("readonly", "readonly");
          var timer = null;
          timer = setTimeout(() => {
            this.removeAttribute("readonly");
            clearTimeout(timer);
          }, 100);
        });
      };
      el.focus();
      // v-focus.noKeyboard 不弹起软键盘
      if (noKeyboard) {
        el.setAttribute("readonly", "readonly");
        var timer = null;
        timer = setTimeout(() => {
          el.removeAttribute("readonly");
          clearTimeout(timer);
        }, 100);
      }
    } catch (error) {
      throw new Error(error);
    }
  }
});
 
 
 
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')