Vue 动态组件 & 插槽 & 自定义指令&ESLint等插件配置

  • 动态组件 component

 <component :is='comName'></component>

data() {

    return {

      comName: 'Left'

    }

  • 防止动态组件被销毁,使用keep-alive保持状态

<keep-alive include='Left,Right'>
      <component :is='comName'></component>
</keep-alive>
  • 当组件被缓存的时候,会自动激活deactivated生命周期

  • 当组件被激活的时候,会自动激活activated生命周期

  • include属性,指定哪些组件可以被缓存

  • exclude属性,指定哪些组件不会被缓存

  • include和exclude不可同时使用

  • 通常通过name属性给组件命名

  • 插槽slot

    1. 具名插槽:v-slot:name   只能用于template或自定义组件标签中,简写为"#name"

    2. 作用域插槽:封装组件时为预留的插槽slot 提供属性对应的值,叫做作用域插槽

      <slot name="content" msg="hellow vue.js" :user="userinfo"></slot>

  • 自定义指令

  1. 私有自定义指令:在每个vue组件中的directive节点中声明

     directives: {
        color: {
          // bind()第一次被绑定到元素时被调用,触发一次
          bind(el,binding) {
            // el.style.color = 'red'
            el.style.color = binding.value
          },
          // 每次触发dom更新时被调用
          update(el, binding) {
            
            el.style.color = binding.value
          }
    
      }
     <h1 v-color>App 根组件</h1>

            函数简写:bind()和update(),逻辑和参数都一样,可以简写

    directives:{
    color(el, binding) {
          el.style.color=binding.value
        }
    }

  • ESLint等插件配置

// prettier插件配置
  "prettier.trailingComma": "none",
  "prettier.semi": false,
  "prettier.printWidth": 300,
  "prettier.singleQuote": true,
  "prettier.arrowParens": "avoid",
  // 设置.vue文件中,html代码的格式化插件
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.ignoreProjectWarning": true,
"vetur.format.defaultFormatterOptions": {
  "js-beautify-html": {
    "wrap_attributes": "false"
  },
  "prettyhtml": {
    "printWidth": 100,
    "singleQuote": true,
    "wrapAttributes": false,
    "sortAttributes": false,
    "arrowParens":"avoid",
    "trailingComma":"none",
    "semi":false,

  }
},
  // ESlINT 插件的配置
  "eslint.codeActionsOnSave": {
    "source.fixAll": true,
  },
//P171中的配置
//创建.prettierrc文件的内容:
//"prettier.configPath":"c:\\Users\\用户名\\.prettierrc
{
    "semi": false,
    "singleQuote": true,
    "bracketSpacing": true
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值