## 全局自定义指令 ### v-copy - 参数类型: any(参数会强制被 String 方法强制转换) - 默认值: '' #### 示例 ```tsx import { NButton, NCard, NFlex, NInput, NInputGroup, NSwitch } from 'naive-ui' const Demo = defineComponent({ name: 'Demo', setup() { const demoCopyValue = ref('hello copy') return { demoCopyValue, } }, render() { return ( 复制 ) }, }) ``` ### v-debounce - 参数类型: DebounceBindingOptions - 默认值: ```ts { trigger: 'click', wait: 500, options: null } ``` #### 示例 ```tsx import { NButton, NCard, NFlex, NInput, NInputGroup, NSwitch } from 'naive-ui' const Demo = defineComponent({ name: 'Demo', setup() { const demoValue = ref(0) const updateDemoValue = () => { demoValue.value++ } return { demoValue, updateDemoValue, } }, render() { return ( 点击执行 我执行了{this.demoValue}次 该方法将延迟 1s 执行 ) }, }) ``` ### v-throttle - 参数类型: ThrottleBindingOptions - 默认值: ```ts { trigger: 'click', wait: 500, options: null } ``` #### 示例 ```tsx import { NButton, NCard, NFlex, NInput, NInputGroup, NSwitch } from 'naive-ui' const Demo = defineComponent({ name: 'Demo', setup() { const demoValue = ref(0) const updateDemoValue = () => { demoValue.value++ } return { demoValue, updateDemoValue, } }, render() { return ( 点击执行 我执行了{this.demoValue}次 该方法 1s 内仅会执行一次 ) }, }) ``` ### v-disabled - 参数类型: boolean - 默认值: false #### Tip > 该指令基于 css 层面进行禁用操作,如果元素含有 `disabled` 属性方法,会尝试使用原生 `disabled` 属性。对于组件库而言,本身就提供了丰富的 `disabled props`,所以应该是优先使用组件自带属性。 #### 示例 ```tsx import { NButton, NCard, NFlex, NForm, NFormItem, NInput, NInputGroup, NSwitch, } from 'naive-ui' const Demo = defineComponent({ name: 'Demo', setup() { const disabledValue = ref(false) return { disabledValue, } }, render() { return ( {{ checked: () => '取消', unchecked: () => '禁用', }} 该指令会强制禁用(通过 css 层面)禁用元素交互。但是 naive ui 组件提供了完整的 disabled 属性,所以在组件库有禁用需求时,直接调用组件库 disabled 属性即可 提交 我是可以被禁用的文本内容 按钮 ) }, }) ```
我执行了{this.demoValue}次
该方法将延迟 1s 执行
该方法 1s 内仅会执行一次
该指令会强制禁用(通过 css 层面)禁用元素交互。但是 naive ui 组件提供了完整的 disabled 属性,所以在组件库有禁用需求时,直接调用组件库 disabled 属性即可
我是可以被禁用的文本内容