• 技术文章 >web前端 >Vue.js

    对比一下Vue指令v-show 和 v-if,聊聊使用场景

    青灯夜游青灯夜游2022-03-28 11:21:42转载218
    本篇文章对比一下Vue指令v-show 和 v-if,介绍一下v-show 和 v-if 的区别,并聊聊v-show 和 v-if 使用场景,希望对大家有所帮助!

    一、v-show 和 v-if 的区别

    二、v-show 和 v-if 使用场景

    三、v-show 和 v-if 原理分析

    export const vShow: ObjectDirective<VShowElement> = {
      beforeMount(el, { value }, { transition }) {
        el._vod = el.style.display === 'none' ? '' : el.style.display
        if (transition && value) {
          transition.beforeEnter(el)
        } else {
          setDisplay(el, value)
        }
      },
      mounted(el, { value }, { transition }) {
        if (transition && value) {
          transition.enter(el)
        }
      },
      updated(el, { value, oldValue }, { transition }) {
        // ...
      },
      beforeUnmount(el, { value }) {
        setDisplay(el, value)
      }
    }
    export const transformIf = createStructuralDirectiveTransform(
      /^(if|else|else-if)$/,
      (node, dir, context) => {
        return processIf(node, dir, context, (ifNode, branch, isRoot) => {
          // ...
          return () => {
            if (isRoot) {
              ifNode.codegenNode = createCodegenNodeForBranch(
                branch,
                key,
                context
              ) as IfConditionalExpression
            } else {
              // attach this branch's codegen node to the v-if root.
              const parentCondition = getParentCondition(ifNode.codegenNode!)
              parentCondition.alternate = createCodegenNodeForBranch(
                branch,
                key + ifNode.branches.length - 1,
                context
              )
            }
          }
        })
      }
    )

    (学习视频分享:vuejs教程web前端

    以上就是对比一下Vue指令v-show 和 v-if,聊聊使用场景的详细内容,更多请关注php中文网其它相关文章!

    声明:本文转载于:掘金社区,如有侵犯,请联系admin@php.cn删除
    专题推荐:Vue 指令 v-show v-if
    上一篇:总结分享:建立VuePress博客后,10 个必做的优化! 下一篇:手把手带你了解Vue中怎么使用filters过滤器?2种用法浅析
    Web大前端开发直播班

    相关文章推荐

    • 如何快速上手vue3,学会这几个API吧!• 什么是Mixin?带你了解Vue中的Mixin混入• 干货分享,带你了解Vue中的Vue.nextTick• VUE3快速上手及常用API函数汇总!• 浅析vue中的生命周期钩子mounted• 总结分享:建立VuePress博客后,10 个必做的优化!

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网