问题描述
我正在尝试使用 Cleave.js 格式化电话号码字段,不起作用,但我似乎不知道为什么.
I'm trying to format a phone number field using Cleave.js and it's not working but I can't seem to figure out why.
我是这样开始的:
import Cleave from 'cleave.js';
var cleave = new Cleave('.phone', {
'phone': true,
'phoneRegionCode': 'CA'
});
我得到了这个错误:
> Uncaught Error: [cleave.js] Please include phone-type-formatter.{country}.js lib
因此,我通过添加以下内容导入了我所缺少的库:
So I imported the library that I was missing by adding:
import CleavePhone from 'cleave.js/dist/addons/cleave-phone.ca';
所以现在我的代码是:
import Cleave from 'cleave.js';
import CleavePhone from 'cleave.js/dist/addons/cleave-phone.ca';
var cleave = new Cleave('.phone', {
'phone': true,
'phoneRegionCode': 'CA'
});
我再也没有收到任何控制台错误,但是电话号码的格式似乎根本不起作用.
I'm not getting any console errors anymore, but the formatting of the phone number doesn't seem to be working at all.
我试图将顺劈斩"的选项更改为一个日期:
I tried to change the options of the Cleave to a date:
var cleave = new Cleave('.phone', {
'date': true,
'datePattern': ['Y', 'm', 'd']
});
输入似乎格式正确.因此,我知道该元素的查询选择器还可以.
And the input seems to format properly. Therefore, I know my query selector for the element is okay.
但是我似乎无法弄清楚为什么我的电话号码格式不正确.
But I can't seem to figure out why my phone number is not formatting properly.
推荐答案
而不是导入,请尝试要求:require('cleave.js/dist/addons/cleave-phone.ca')
Instead of importing, try requiring: require('cleave.js/dist/addons/cleave-phone.ca')
这篇关于Cleave.js电话CA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!