- 使用watch方法
还可以输入{{this.titleMaxLength - this.title.length}}
- 自定义指令
- 组件内注册
还可以输入{{this.titleMaxLength - this.title.length >= 0 ?this.titleMaxLength - this.title.length : 0 }}
全局注册
// man.js
Vue.directive('limitTextLen', {
bind: function () {},
inserted: function () {},
update: function (el, binding) {
if (el.value.length >= binding.value) {
el.value = el.value.slice(0, binding.value);
}
},
componentUpdated: function () {},
unbind: function () {}
});