当前位置: 首页 > wzjs >正文

做网站需要什么技术支持新媒体培训

做网站需要什么技术支持,新媒体培训,广州网站建设网络推广公司,成功做网站一、自定义指令 1、自己封装指令 什么是指令?指令本质上就是DOM功能的一种抽象封装。 如果有一些DOM功能经常用,但是Vue没有提供相关指令,建议自己封装。 2、自定义全局指令 使用Vue.directive(指令名, function() {})定义全局指令。 3、…

一、自定义指令

1、自己封装指令
什么是指令?指令本质上就是DOM功能的一种抽象封装。

如果有一些DOM功能经常用,但是Vue没有提供相关指令,建议自己封装。

2、自定义全局指令
使用Vue.directive('指令名', function() {})定义全局指令。

3、自定义局部指令
使用directives: {}定义局部指令,只能在当前组件中使用。

(1)使用function写法

directives: {// function写法'color': function(el, binding, vnode) {console.log('---el', el) // 指令所对应的DOM节点console.log('---binding', binding) // 绑定的值/表达式console.log('---vnode', vnode) // 当前的虚拟DOMel.style.color = binding.value}
}

接收3个参数:
el:指令所对应的DOM节点
binding:绑定的值/表达式
vnode:当前的虚拟DOM

(2)使用对象写法

directives: {// function写法'color': function(el, binding, vnode) {console.log('---el', el) // 指令所对应的DOM节点console.log('---binding', binding) // 绑定的值/表达式console.log('---vnode', vnode) // 当前的虚拟DOMel.style.color = binding.value},// 对象写法'color2': {bind(el, binding) { // 绑定cc变量的时候el.style.color = binding.value},update(el, binding) { // 修改cc变量的时候el.style.color = binding.value}}
}

还有其它的钩子。

注:function写法,等价于bind + update这两个。

二、例子代码

自己封装一个指令v-form,类似于v-model指令实现双向绑定。
必须要用虚拟DOM的上下文实现。

<html>
<head><title>自定义指令</title><style></style>
</head>
<body><div id="app"><h1 v-color='"red"'>测试</h1><h1 v-color='"blue"'>测试</h1><h1 v-color2="cc">测试</h1><input type="text" v-form.lazy="name" /></div><script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script><script>Vue.directive ('form', {bind(el, binding, vnode) {console.log('---el', el)console.log('---binding', binding)console.log('---vnode', vnode)// 解构赋值const { lazy } = binding.modifiers// v-bind:value// 指令在绑值的时候,改上下文中的值el.value = vnode.context[binding.expression]// v-on:input// 实现双向绑定el.addEventListener(lazy?'blur':'input', function(ev){console.log('---事件', ev.target.value)vnode.context[binding.expression] = ev.target.value})},update(el, binding, vnode) {// 实现双向绑定el.value = vnode.context[binding.expression]}})const app = new Vue({data() {return {cc: "green",name: '张三'}},directives: {// function写法'color': function(el, binding, vnode) {//console.log('---el', el) // 指令所对应的DOM节点//console.log('---binding', binding) // 绑定的值/表达式//console.log('---vnode', vnode) // 当前的虚拟DOMel.style.color = binding.value},// 对象写法'color2': {bind(el, binding) { // 绑定cc变量的时候el.style.color = binding.value},update(el, binding) { // 修改cc变量的时候el.style.color = binding.value}}}})app.$mount('#app')</script></body>
</html>

http://www.dtcms.com/wzjs/474359.html

相关文章:

  • 免费创建社区论坛网站网站关键词上首页
  • 用手机制作动画的app揭阳百度seo公司
  • 华为云建站靠谱吗百度云搜索引擎 百度网盘
  • wdcp创建多个网站网站外链是什么意思
  • 模板网站会员百度怎样发布信息
  • wordpress中文网站模板千川推广官网
  • 手机商城系统哪个好德阳网站seo
  • 网站优化三要素美发培训职业学校
  • 成都网站建设新闻酒泉网站seo
  • 广州做网站信科分公司app软件推广怎么做
  • 网站建设品牌营销seo关键词优化技巧
  • 推荐网站建设推广百度网址大全下载安装
  • 合肥商城网站建设中国关键词官网
  • 网络营销推广主要做什么?邵阳seo优化
  • 购物网站静态页面模板北京seo设计公司
  • 福建建设信息网站营销推广网
  • 中山网站建设公司哪家好app接入广告变现
  • 制作网站的专业公司长春网站建设路
  • 做app和做网站的区别百度的网址
  • 搜索优化整站优化搜索引擎网站优化和推广方案
  • 制作展示型网站的公司凡科建站代理
  • 做中小型网站最好的架构有什么好用的搜索引擎
  • 企业网站建设需要哪些设备seo数据分析哪些方面
  • 网站后台 批量上传外包公司是正规公司吗
  • 福建省建设厅网站节能办响应式网站模板的应用
  • 政府门户网站建设的目的和意义生成关键词的软件免费
  • 网站 网安备案查询线上it培训机构
  • 杭州做肉松饼的网站有多少家百度推广服务
  • 免费vip影视网站怎么做的旺道优化软件
  • 商标交易周口seo