程序员鸡皮

文章 分类 评论
61 3 11

站点介绍

一名PHP全栈程序员的日常......

Vue3自定义指令参数修饰符值(3)

abzzp 2024-08-31 395 0条评论 前端 vue

首页 / 正文
本站是作为记录一名北漂程序员编程学习以及日常的博客,欢迎添加微信BmzhbjzhB咨询交流......

发布于2024-07-04

自定义指令参数修饰符值

在vue3中我们如何获取自定义的参数的内容,并根据业务来修改展示的内容呢,需要依靠mounted方法中的bindings参数来获取。

参考实例
directives/unit.js文件

export default function directiveUnit(app){
  app.directive("unit",{
    mounted(el,bindings){
      const defaultText = el.textContent
      let unit = bindings.value
      if(!unit){
        unit = "¥"
      }
      el.textContent = unit + defaultText;
    }
  })
}

同时我们需要在directives/index.js中引入

import directiveUnit from "./unit"

export default function directives(app) {
  directiveUnit(app)
}

这里是我们的示例文件

<template>
  <div class="app">
    <!-- 1.参数-修饰符-值  -->
     <h2 v-why:kobe.abc.cba="message">哈哈哈</h2>
     <!-- 2.价格拼接单位符号 -->
      <h2 v-unit>{{ 111 }}</h2>
  </div>
</template>  
<script setup>
import { ref } from 'vue';

const counter = ref(0)

const message = 'Hello world';
const vWhy = {
  mounted(el,bindings){
    console.log(bindings);
    el.textContent = bindings.value;
  }
}
</script>
<style scoped>
</style> 

感谢大家观看,我们下次再见

评论(0)

最新评论

  • See details

    of course like your web site but you need to test the spelling on quite a few of your posts. A number of them are rife with spelling problems and I in finding it very troublesome to inform the reality nevertheless I will surely come again again.

  • 晚夜

    新年快乐!

  • abzzp

    十天看一部剧,还可以吧[[呲牙]]

  • ab

    @梦不见的梦 行,谢谢提醒,我优化一下

  • 梦不见的梦

    网站的速度有待提升,每次打开都要转半天还进不来呢

  • abzzp

    @React实战爱彼迎项目(二) - 程序员鸡皮 哪里有问题了,报错了吗?[[微笑]]

  • abzzp

    @Teacher Du 那是怕你们毕不了业,我大学那会儿给小礼品[[发呆]]

  • Teacher Du

    我们大学那会,献血还给学分~

  • @ab 我想去学网安,比如网警,但分也贼高😕

  • ab

    @夜 加油,你一样也可以成为程序员的,需要学习资料可以V我

日历

2025年02月

      1
2345678
9101112131415
16171819202122
232425262728 

文章目录

推荐关键字: vue JavaScript React Golang 观后感 ES6 SEO 读后感

站点公告
本站是作为记录一名北漂程序员编程学习以及日常的博客,欢迎添加微信BmzhbjzhB咨询交流......
点击小铃铛关闭
配色方案