49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import { createApp } from 'vue'
|
|
import './style.css'
|
|
import App from './App.vue'
|
|
import '@unocss/reset/sanitize/sanitize.css'
|
|
import '@unocss/reset/sanitize/assets.css'
|
|
import 'virtual:uno.css'
|
|
import "vant/es/image-preview/style";
|
|
import { ImagePreview } from 'vant';
|
|
import Vconsole from 'vconsole'
|
|
new Vconsole()
|
|
import router from "./router/index.js";
|
|
const app = createApp(App);
|
|
app.use(router);
|
|
app.use(ImagePreview);
|
|
|
|
app.directive('no-space', {
|
|
mounted(el) {
|
|
el.addEventListener('input', (e) => {
|
|
const originalValue = e.target.value;
|
|
const newValue = originalValue.replace(/\s/g, '');
|
|
if (originalValue !== newValue) {
|
|
e.target.value = newValue;
|
|
e.target.dispatchEvent(new Event('input'));
|
|
}
|
|
});
|
|
}
|
|
})
|
|
// 注册全局自定义指令
|
|
app.directive('decimal', {
|
|
mounted(el) {
|
|
el.addEventListener('input', (event) => {
|
|
// 获取当前输入的值
|
|
let value = event.target.value;
|
|
|
|
// 匹配有效的数字(最多一位小数)
|
|
const regex = /^\d*\.?\d{0,1}$/;
|
|
|
|
if (!regex.test(value)) {
|
|
// 如果不匹配,将输入值设置为最后一次有效输入的值
|
|
event.target.value = el._lastValidValue || '';
|
|
} else {
|
|
// 如果匹配,保存该有效输入值
|
|
el._lastValidValue = value;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
app.mount('#app');
|