当前位置:网站首页>atguigu----16-自定义指令
atguigu----16-自定义指令
2022-06-24 06:44:00 【张 邵】
自定义指令总结:
一、定义语法:
(1).局部指令:
new Vue({ new Vue({
directives:{指令名:配置对象} 或 directives{指令名:回调函数}
}) })
(2).全局指令:
Vue.directive(指令名,配置对象) 或 Vue.directive(指令名,回调函数)
二、配置对象中常用的3个回调:
(1).bind:指令与元素成功绑定时调用。
(2).inserted:指令所在元素被插入页面时调用。
(3).update:指令所在模板结构被重新解析时调用。
三、备注:
1.指令定义时不加v-,但使用时要加v-;
2.指令名如果是多个单词,要使用kebab-case命名方式,不要用camelCase命名。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>自定义指令</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 需求1:定义一个v-big指令,和v-text功能类似,但会把绑定的数值放大10倍。 需求2:定义一个v-fbind指令,和v-bind功能类似,但可以让其所绑定的input元素默认获取焦点。 自定义指令总结: 一、定义语法: (1).局部指令: new Vue({ new Vue({ directives:{指令名:配置对象} 或 directives{指令名:回调函数} }) }) (2).全局指令: Vue.directive(指令名,配置对象) 或 Vue.directive(指令名,回调函数) 二、配置对象中常用的3个回调: (1).bind:指令与元素成功绑定时调用。 (2).inserted:指令所在元素被插入页面时调用。 (3).update:指令所在模板结构被重新解析时调用。 三、备注: 1.指令定义时不加v-,但使用时要加v-; 2.指令名如果是多个单词,要使用kebab-case命名方式,不要用camelCase命名。 -->
<!-- 准备好一个容器-->
<div id="root">
<h2>{
{name}}</h2>
<h2>当前的n值是:<span v-text="n"></span> </h2>
<!-- <h2>放大10倍后的n值是:<span v-big-number="n"></span> </h2> -->
<h2>放大10倍后的n值是:<span v-big="n"></span> </h2>
<button @click="n++">点我n+1</button>
<hr/>
<input type="text" v-fbind:value="n">
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false //定义全局指令 /* Vue.directive('fbind',{ //指令与元素成功绑定时(一上来) bind(element,binding){ element.value = binding.value }, //指令所在元素被插入页面时 inserted(element,binding){ element.focus() }, //指令所在的模板被重新解析时 update(element,binding){ element.value = binding.value } }) */ new Vue({
el:'#root', data:{
name:'尚硅谷', n:1 }, directives:{
//big函数何时会被调用?1.指令与元素成功绑定时(一上来)。2.指令所在的模板被重新解析时。 /* 'big-number'(element,binding){ // console.log('big') element.innerText = binding.value * 10 }, */ big(element,binding){
console.log('big',this) //注意此处的this是window // console.log('big') element.innerText = binding.value * 10 }, fbind:{
//指令与元素成功绑定时(一上来) bind(element,binding){
element.value = binding.value }, //指令所在元素被插入页面时 inserted(element,binding){
element.focus() }, //指令所在的模板被重新解析时 update(element,binding){
element.value = binding.value } } } }) </script>
</html>
边栏推荐
- What should I pay attention to after the live broadcast system source code is set up?
- What is automated testing? What software projects are suitable for automated testing?
- Win11 points how to divide disks? How to divide disks in win11 system?
- 与(&&)逻辑或(||),动态绑定结合三目运算
- Extend ado Net to realize object-oriented CRUD (.Net core/framework)
- [WUSTCTF2020]alison_ likes_ jojo
- Tidb operator source code reading (IV) control cycle of components
- Global and Chinese market of offshore furnaces 2022-2028: Research Report on technology, participants, trends, market size and share
- 简单使用Modbus转BACnet网关教程
- Tutorial on simple use of Modbus to BACnet gateway
猜你喜欢
![[image fusion] multi focus and multi spectral image fusion based on pixel saliency and wavelet transform with matlab code](/img/78/5d8ad56d4ff1451590cc8676893f05.png)
[image fusion] multi focus and multi spectral image fusion based on pixel saliency and wavelet transform with matlab code

jarvisoj_ level2
![[WUSTCTF2020]alison_ likes_ jojo](/img/a9/dcc6f524772cd0b8781289cbaef63f.png)
[WUSTCTF2020]alison_ likes_ jojo

与(&&)逻辑或(||),动态绑定结合三目运算

How to turn on win11 notebook power saving mode? How to open win11 computer power saving mode

Camera calibration (calibration purpose and principle)
![[WUSTCTF2020]爬](/img/b6/4a0582144c3125e7a0666bbbbfe29d.png)
[WUSTCTF2020]爬
![[tips] use the deep learning toolbox of MATLAB deepnetworkdesigner to quickly design](/img/74/f615191715a9ac58a8546f8d1e8f8d.png)
[tips] use the deep learning toolbox of MATLAB deepnetworkdesigner to quickly design

Blue Bridge Cup seven segment code (dfs/ shape pressing + parallel search)

Only two lines are displayed, and the excess part is displayed with Ellipsis
随机推荐
buuctf misc 从娃娃抓起
When MFC uses the console, the project path cannot have spaces or Chinese, otherwise an error will be reported. Lnk1342 fails to save the backup copy of the binary file to be edited, etc
Reconfiguration of nebula integration testing framework based on BDD theory (Part 2)
[OGeek2019]babyrop
湖北专升本-湖师计科
第三方软件测试公司如何选择?2022国内软件测试机构排名
简单的折射效果
Learning to use BACnet gateway of building control system is not so difficult
Global and Chinese market of anion sanitary napkins 2022-2028: Research Report on technology, participants, trends, market size and share
Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
get_started_3dsctf_2016
[image fusion] image fusion based on NSST and PCNN with matlab code
The fund management of London gold is more important than others
[WordPress website] 5 Set code highlight
简单使用Modbus转BACnet网关教程
[MRCTF2020]千层套路
Muxvlan principle, Huawei MUX VLAN experimental configuration
Hubei College Upgraded to undergraduate - Hushi family planning department
L2tp/ipsec one click installation script
[DDCTF2018](╯°□°)╯︵ ┻━┻