GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 第 147 题:v-if、v-show、v-html 的原理是什么,它是如何封装的? · Issue #307 · Advanced-Frontend/Daily-Interview-Question

第 147 题:v-if、v-show、v-html 的原理是什么,它是如何封装的? #307

New issue
Copy link
New issue
Copy link
Open
Open
第 147 题:v-if、v-show、v-html 的原理是什么,它是如何封装的?#307
Copy link
Labels
Vue

Description

@yygmind
yygmind
opened on Oct 31, 2019
Issue body actions
No description provided.
Reacted by leader755, zhangdiz, GuoYuFu123, 陈旧, helloyulife, gitDengXiao, Matt Dun, developmentCode, Charlie, tzc and 2 more

Activity

  1. Leader755 commented on Oct 31, 2019

    @Leader755
    Leader755
    on Oct 31, 2019
    More actions

    v-if:当隐藏结构时该结构会直接从整个dom树中移除;

    v-show:当隐藏结构时是在该结构的style中加上display:none,结构依然保留。

    Reacted by hyyy, Jesse, Loading, Cammy Becker, YangXianZhao, Sun, lx, FunnyBoyCN, tinyThing, CHEETO and 36 more
  2. zeroone001 commented on Oct 31, 2019

    @zeroone001
    zeroone001
    on Oct 31, 2019
    More actions

    v-if: Watcher监听数据变化,然后,render函数生成VNode对象,patch方法对比新旧VNode, DOM Diff 算法修改真正的DOM元素

    Reacted by Loading, LYS, lx, myBook, gnaful, okevinok, jsdzll and yuzhian
    Reacted by carpenterzoe
    Reacted by okevinok
  3. brady0316 commented on Nov 7, 2019

    @brady0316
    brady0316
    on Nov 7, 2019
    More actions

    v-if会调用addIfCondition方法,生成vnode的时候会忽略对应节点,render的时候就不会渲染;
    v-show会生成vnode,render的时候也会渲染成真实节点,只是在render过程中会在节点的属性中修改show属性值,也就是常说的display;
    v-html会先移除节点下的所有节点,调用html方法,通过addProp添加innerHTML属性,归根结底还是设置innerHTML为v-html的值

    Reacted by mapleChain, yi, Vera1128, Xu Jun, Matt Dun, lpx, qq635030106, gitDengXiao, www, zqc and 60 more
    Reacted by boboxu, Luka Ceng and 风间
    Reacted by lpp
    Reacted by garrettzxd, wjj5728 and Azir1
  4. yygmind
    added
    Vue
    on Dec 16, 2019
  5. JaykeyGuo commented on Oct 27, 2020

    @JaykeyGuo
    JaykeyGuo
    on Oct 27, 2020
    More actions

    v-if会调用addIfCondition方法,生成vnode的时候会忽略对应节点,render的时候就不会渲染;
    v-show会生成vnode,render的时候也会渲染成真实节点,只是在render过程中会在节点的属性中修改show属性值,也就是常说的display;
    v-html会先移除节点下的所有节点,调用html方法,通过addProp添加innerHTML属性,归根结底还是设置innerHTML为v-html的值

    所以在使用v-html的时候可能会存在XSS攻击的漏洞,被植入可执行的脚本

  6. yangmin4052 commented on Dec 23, 2020

    @yangmin4052
    yangmin4052
    on Dec 23, 2020
    More actions

    如何根据v-if的原理写一个v-permission,要求切换权限时节点可以被删除,也可以在删除后被添加回来

    Reacted by SeaCui
  7. yft commented on Aug 21, 2021

    @yft
    yft
    on Aug 21, 2021
    More actions

    如何根据v-if的原理写一个v-permission,要求切换权限时节点可以被删除,也可以在删除后被添加回来

    https://stackoverflow.com/questions/43003976/a-custom-directive-similar-to-v-if-in-vuejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Vue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.