当前位置:网站首页>Atguigu---16-custom instruction
Atguigu---16-custom instruction
2022-06-24 08:02:00 【Zhangshao】
List of articles
Custom Instruction Summary :
One 、 Definition grammar :
(1). Local command :
new Vue({ new Vue({
directives:{ Instruction name : Configuration object } or directives{ Instruction name : Callback function }
}) })
(2). Global instructions :
Vue.directive( Instruction name , Configuration object ) or Vue.directive( Instruction name , Callback function )
Two 、 Commonly used in configuration objects 3 A callback :
(1).bind: Called when the instruction successfully binds to the element .
(2).inserted: Called when the element of the instruction is inserted into the page .
(3).update: Called when the template structure of the instruction is re parsed .
3、 ... and 、 remarks :
1. Instructions are defined without v-, But use it with v-;
2. If the instruction name is more than one word , To use kebab-case Naming method , Do not use camelCase name .
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Custom instruction </title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- demand 1: Define a v-big Instructions , and v-text The function is similar to , But it will enlarge the bound value 10 times . demand 2: Define a v-fbind Instructions , and v-bind The function is similar to , But you can make it bound input Element gets focus by default . Custom Instruction Summary : One 、 Definition grammar : (1). Local command : new Vue({ new Vue({ directives:{ Instruction name : Configuration object } or directives{ Instruction name : Callback function } }) }) (2). Global instructions : Vue.directive( Instruction name , Configuration object ) or Vue.directive( Instruction name , Callback function ) Two 、 Commonly used in configuration objects 3 A callback : (1).bind: Called when the instruction successfully binds to the element . (2).inserted: Called when the element of the instruction is inserted into the page . (3).update: Called when the template structure of the instruction is re parsed . 3、 ... and 、 remarks : 1. Instructions are defined without v-, But use it with v-; 2. If the instruction name is more than one word , To use kebab-case Naming method , Do not use camelCase name . -->
<!-- Prepare a container -->
<div id="root">
<h2>{
{name}}</h2>
<h2> Current n The value is :<span v-text="n"></span> </h2>
<!-- <h2> Zoom in 10 After times n The value is :<span v-big-number="n"></span> </h2> -->
<h2> Zoom in 10 After times n The value is :<span v-big="n"></span> </h2>
<button @click="n++"> Am I n+1</button>
<hr/>
<input type="text" v-fbind:value="n">
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // Define global instructions /* Vue.directive('fbind',{ // When an instruction is successfully bound to an element ( at first ) bind(element,binding){ element.value = binding.value }, // When the element of the instruction is inserted into the page inserted(element,binding){ element.focus() }, // When the template of the instruction is parsed again update(element,binding){ element.value = binding.value } }) */ new Vue({
el:'#root', data:{
name:' Silicon Valley ', n:1 }, directives:{
//big When will the function be called ?1. When an instruction is successfully bound to an element ( at first ).2. When the template of the instruction is parsed again . /* 'big-number'(element,binding){ // console.log('big') element.innerText = binding.value * 10 }, */ big(element,binding){
console.log('big',this) // Pay attention to this yes window // console.log('big') element.innerText = binding.value * 10 }, fbind:{
// When an instruction is successfully bound to an element ( at first ) bind(element,binding){
element.value = binding.value }, // When the element of the instruction is inserted into the page inserted(element,binding){
element.focus() }, // When the template of the instruction is parsed again update(element,binding){
element.value = binding.value } } } }) </script>
</html>
边栏推荐
猜你喜欢

研究生英语期末考试复习

Review of postgraduate English final exam

模型效果优化,试一下多种交叉验证的方法(系统实操)

基于Distiller的模型压缩工具简介

宝塔面板安装php7.2安装phalcon3.3.2

不止于观测|阿里云可观测套件正式发布

Signature analysis of app x-zse-96 in a Q & a community

Graphmae - - lecture rapide des documents

Selenium IDE的安装以及使用

Latest news of awtk: new usage of grid control
随机推荐
Chapter 3: drawing triangles
Duilib display memory picture
Error "computing failed in `stat\u summary\u hex() `"
What kind of experience is it when the Institute earns 20000 yuan a month!
Graphmae ---- quick reading of papers
Standing at the center of the storm: how to change the engine of Tencent
交友相亲类软件是如何割你韭菜的
站在风暴中心:如何给飞奔中的腾讯更换引擎
Oracle advanced SQL qualified query
语料库数据处理个案实例(句子检索相关个案)
从 jsonpath 和 xpath 到 SPL
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
Resolution error: LNK2019 unresolved external symbol
闲谈:3AC到底发生了什么?
From jsonpath and XPath to spl
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
Live wire, neutral wire and ground wire. Do you know the function of these three wires?
New features of PHP: bytecode cache and built-in server
慕思股份在深交所上市:毛利率持续下滑,2022年一季度营销失利
1-4metasploitable2介绍