首页 > 其他分享 >Vue 中的 slot 插槽

Vue 中的 slot 插槽

时间:2023-09-16 15:02:40浏览次数:36  
标签:slot Category Vue 插槽 App vue 组件

目录

  • 一:知识点说明
  • 二:不使用插槽效果
  • 1:界面效果
  • 2:代码结构
  • 3:代码内容
  • 三:使用插槽组件(默认插槽 slot)
  • 1:界面效果
  • 2:代码结构
  • 3:代码内容
  • 四:使用插槽组件(具名插槽slot)
  • 1:看界面效果
  • 2:代码结构
  • 3:代码内容
  • 五:作用域插槽(slot-scope /scope)
  • 1:看界面效果
  • 2:代码结构
  • 3:代码内容

 

一:知识点说明


## 插槽

1. 作用:让父组件可以向子组件指定位置插入html结构,也是一种组件间通信的方式,适用于 <strong style="color:red">父组件 ===> 子组件</strong> 。

2. 分类:默认插槽、具名插槽、作用域插槽

3. 使用方式:

   1. 默认插槽:

      ```vue
      父组件中:
              <Category>
                 <div>html结构1</div>
              </Category>
      子组件中:
              <template>
                  <div>
                     <!-- 定义插槽 -->
                     <slot>插槽默认内容...</slot>
                  </div>
              </template>
      ```

   2. 具名插槽:

      ```vue
      父组件中:
              <Category>
                  <template slot="center">
                    <div>html结构1</div>
                  </template>

                  <template v-slot:footer>
                     <div>html结构2</div>
                  </template>
              </Category>
      子组件中:
              <template>
                  <div>
                     <!-- 定义插槽 -->
                     <slot name="center">插槽默认内容...</slot>
                     <slot name="footer">插槽默认内容...</slot>
                  </div>
              </template>
      ```

   3. 作用域插槽:

      1. 理解:<span style="color:red">数据在组件的自身,但根据数据生成的结构需要组件的使用者来决定。</span>(games数据在Category组件中,但使用数据所遍历出来的结构由App组件决定)

      2. 具体编码:

         ```vue
         父组件中:
         		<Category>
         			<template scope="scopeData">
         				<!-- 生成的是ul列表 -->
         				<ul>
         					<li v-for="g in scopeData.games" :key="g">{{g}}</li>
         				</ul>
         			</template>
         		</Category>

         		<Category>
         			<template slot-scope="scopeData">
         				<!-- 生成的是h4标题 -->
         				<h4 v-for="g in scopeData.games" :key="g">{{g}}</h4>
         			</template>
         		</Category>
         子组件中:
                 <template>
                     <div>
                         <slot :games="games"></slot>
                     </div>
                 </template>

                 <script>
                     export default {
                         name:'Category',
                         props:['title'],
                         //数据在子组件自身
                         data() {
                             return {
                                 games:['红色警戒','穿越火线','劲舞团','超级玛丽']
                             }
                         },
                     }
                 </script>
         ```
   ```

   ```






二:不使用插槽效果


1:界面效果

Vue 中的 slot 插槽_Vue


2:代码结构

Vue 中的 slot 插槽_插槽_02


3:代码内容


3.1:vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  pages:{
    index:{
      // 入口
      entry:'src/main.js',
    },
  },
  //配置vue脚手架的代理服务器:开启代理服务器  此处代理服务器默认与 该脚手架启动的模拟的前端服务器 端口相同:8080
  // 方式一
  /*
   devServer:{
     proxy:'http://localhost:5000/'
  },
 */
  // 方式二 
   devServer:{
      proxy:{
           //  '/api': 请求前缀 
          '/api':{
                    target:'http://localhost:5000/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/api':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  } ,
           //  '/api': 请求前缀 
          '/demo':{
                    target:'http://localhost:5001/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/demo':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  }
      }
   },
   transpileDependencies: true,
   lintOnSave:false, /*关闭语法检查*/


})

3.2:main.js

//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'

// 引入 vue插件: vue-recource
import vueResource from 'vue-resource'

//关闭Vue生产提示
Vue.config.productionTip=false;

// 使用插件
Vue.use(vueResource);

// 创建Vm
const vm = new Vue(  {
        el:'#app',
        render: (h) => h(App),
        //添加全局事件总线对象
        beforeCreate(){
             Vue.prototype.$bus=this;
        }
   });

3.3:App.vue

<template>
  <div class="container">
    <Category title="美食"  :listData="foods"/>
    <Category title="游戏"  :listData="games"/>
    <Category title="电影"  :listData="films"/>
</div>
</template>
<script>
import Category from './components/Category.vue'


export default {
  /* 组件名 */
  name: 'App',
  /* mixin(混入)  */
  mixins: [],
  /* 配置声明子组件  */
  components: {Category},
  /* 组件间数据、方法传值接收区  */
  props: [],
  /* 数据对象:数据赋值声明  */
  data() {
    return {
      foods:['川味火锅','烧烤羊肉','炭火烤肉','清蒸海鲜'],
      games:['梦幻西游','大话西游','征途2','传奇'],
      films:['《为人师表》','《刺客》','《喜欢你》','《桃姐》']

    }
  },
  /* 计算属性:计算区  */
  computed: {},
  /* 检测区  */
  watch: {},
  /*   */
  created() { },
  /*  挂载区 */
  mounted() { },
  /*  方法区 */
  methods: {}
}
</script>

<style  lang="css">
    .container{
      display:flex;/* div 浮动 */
      justify-content: space-around; /* 主轴对齐 */
    }

</style>

3.4:Category.vue

<template>
  <div class="category">
    <h3>{{title}}分类</h3>
    <ul>

        <li  v-for="(item,index) in listData"  :key ="index">{{item}}</li>

    </ul>
  </div>
</template>


<script>
export default {
/* 组件名 */
  name: 'Category',
/* mixin(混入)  */
  mixins: [],
/* 配置声明子组件  */
  components: {},
/* 组件间数据、方法传值接收区  */
  props: ['listData','title'],
/* 数据对象:数据赋值声明  */
  data () {
    return {

    }
  },
/* 计算属性:计算区  */
  computed: {},
/* 检测区  */
  watch: {},
/*   */
  created () {},
/*  挂载区 */
  mounted () {},
/*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">

.category{
    background-color: skyblue;
    width:200px;
    height:300px;
}
h3{
    text-align:center;
    background-color: orange ;
}

</style>





三:使用插槽组件(默认插槽 slot)


1:界面效果

Vue 中的 slot 插槽_插槽_03


2:代码结构


Vue 中的 slot 插槽_插槽_04


3:代码内容

3.1 :vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  pages:{
    index:{
      // 入口
      entry:'src/main.js',
    },
  },
  //配置vue脚手架的代理服务器:开启代理服务器  此处代理服务器默认与 该脚手架启动的模拟的前端服务器 端口相同:8080
  // 方式一
  /*
   devServer:{
     proxy:'http://localhost:5000/'
  },
 */
  // 方式二 
   devServer:{
      proxy:{
           //  '/api': 请求前缀 
          '/api':{
                    target:'http://localhost:5000/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/api':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  } ,
           //  '/api': 请求前缀 
          '/demo':{
                    target:'http://localhost:5001/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/demo':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  }
      }
   },
   transpileDependencies: true,
   lintOnSave:false, /*关闭语法检查*/


})

3.2:main.js

//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'

// 引入 vue插件: vue-recource
import vueResource from 'vue-resource'

//关闭Vue生产提示
Vue.config.productionTip=false;

// 使用插件
Vue.use(vueResource);

// 创建Vm
const vm = new Vue(  {
        el:'#app',
        render: (h) => h(App),
        //添加全局事件总线对象
        beforeCreate(){
             Vue.prototype.$bus=this;
        }
   });

3.3:App.vue

<template>
  <div class="container">
    <Category title="美食"   >
      <img  src="https://s3.ax1x.com/2021/01/16/srJlq0.jpg" alt="" >
    </Category>
    <Category title="游戏"   >
      <ul>
          <li  v-for="(g,index) in games"  :key ="index">{{g}}</li>
      </ul>
    </Category>
    <Category title="电影"   >
      <video  controls src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>
    </Category>
</div>
</template>


<script>
import Category from './components/Category.vue'


export default {
  /* 组件名 */
  name: 'App',
  /* mixin(混入)  */
  mixins: [],
  /* 配置声明子组件  */
  components: {Category},
  /* 组件间数据、方法传值接收区  */
  props: [],
  /* 数据对象:数据赋值声明  */
  data() {
    return {
      foods:['川味火锅','烧烤羊肉','炭火烤肉','清蒸海鲜'],
      games:['梦幻西游','大话西游','征途2','传奇'],
      films:['《为人师表》','《刺客》','《喜欢你》','《桃姐》']

    }
  },
  /* 计算属性:计算区  */
  computed: {},
  /* 检测区  */
  watch: {},
  /*   */
  created() { },
  /*  挂载区 */
  mounted() { },
  /*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">
    .container{
      display:flex;/* div 浮动 */
      justify-content: space-around; /* 主轴对齐 */
    }
    img{
      width:100%;
    }

    video{
       width:100%;
    }
</style>

3.4:Category.vue

<template>
  <div class="category">
    <h3>{{title}}分类</h3>
    <!-- 定义一个插槽(挖个坑,等着组件的使用者进行填充) -->
    <slot></slot>
  </div>
</template>


<script>
export default {
/* 组件名 */
  name: 'Category',
/* mixin(混入)  */
  mixins: [],
/* 配置声明子组件  */
  components: {},
/* 组件间数据、方法传值接收区  */
  props: [ 'title'],
/* 数据对象:数据赋值声明  */
  data () {
    return {

    }
  },
/* 计算属性:计算区  */
  computed: {},
/* 检测区  */
  watch: {},
/*   */
  created () {},
/*  挂载区 */
  mounted () {},
/*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">

.category{
    background-color: skyblue;
    width:200px;
    height:300px;
}
h3{
    text-align:center;
    background-color: orange ;
}

</style>





四:使用插槽组件(具名插槽slot)



1:看界面效果

Vue 中的 slot 插槽_数据_05


2:代码结构

Vue 中的 slot 插槽_数据_06


3:代码内容

3.1 vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  pages:{
    index:{
      // 入口
      entry:'src/main.js',
    },
  },
  //配置vue脚手架的代理服务器:开启代理服务器  此处代理服务器默认与 该脚手架启动的模拟的前端服务器 端口相同:8080
  // 方式一
  /*
   devServer:{
     proxy:'http://localhost:5000/'
  },
 */
  // 方式二 
   devServer:{
      proxy:{
           //  '/api': 请求前缀 
          '/api':{
                    target:'http://localhost:5000/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/api':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  } ,
           //  '/api': 请求前缀 
          '/demo':{
                    target:'http://localhost:5001/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/demo':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  }
      }
   },
   transpileDependencies: true,
   lintOnSave:false, /*关闭语法检查*/


})

3.2:main.js

//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'

// 引入 vue插件: vue-recource
import vueResource from 'vue-resource'

//关闭Vue生产提示
Vue.config.productionTip=false;

// 使用插件
Vue.use(vueResource);

// 创建Vm
const vm = new Vue(  {
        el:'#app',
        render: (h) => h(App),
        //添加全局事件总线对象
        beforeCreate(){
             Vue.prototype.$bus=this;
        }
   });

3.3:App.vue

<template>
  <div class="container">
    <Category title="美食"   >
      <img slot="center" src="https://s3.ax1x.com/2021/01/16/srJlq0.jpg" alt="" >
      <a slot="footer" href="">更多美食</a>
    </Category>
    <Category title="游戏"   >
        <ul slot="center">
            <li  v-for="(g,index) in games"  :key ="index">{{g}}</li>
        </ul>
        <div class="foot" slot="footer">
            <a   href="">单机游戏</a>
            <a   href="">网络游戏</a>
        </div>
    </Category>
    <Category title="电影"   >
      <video slot="center" controls src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>
      <template  v-slot:footer >  <!--  v-slot:footer  相当于    slot="footer" 且  该方法只能用户在 template组件上 -->
          <div class="foot" >
              <a   href="">经典</a>
              <a   href="">热门</a>
              <a   href="">推荐</a>
          </div>
          <h4 >欢迎前来观影</h4>
    </template>
    </Category>
</div>
</template>


<script>
import Category from './components/Category.vue'


export default {
  /* 组件名 */
  name: 'App',
  /* mixin(混入)  */
  mixins: [],
  /* 配置声明子组件  */
  components: {Category},
  /* 组件间数据、方法传值接收区  */
  props: [],
  /* 数据对象:数据赋值声明  */
  data() {
    return {
      foods:['川味火锅','烧烤羊肉','炭火烤肉','清蒸海鲜'],
      games:['梦幻西游','大话西游','征途2','传奇'],
      films:['《为人师表》','《刺客》','《喜欢你》','《桃姐》']

    }
  },
  /* 计算属性:计算区  */
  computed: {},
  /* 检测区  */
  watch: {},
  /*   */
  created() { },
  /*  挂载区 */
  mounted() { },
  /*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">
    .container,.foot{
      display:flex;/* div 浮动 */
      justify-content: space-around; /* 主轴对齐 */
    }
    img{
      width:100%;
    }
    h4{
      text-align:center;
    }
    video{
       width:100%;
    }
</style>

3.4:Category.vue

<template>
  <div class="category">
    <h3>{{title}}分类</h3>
    <!-- 定义一个插槽(挖个坑,等着组件的使用者进行填充) -->
    <slot name="center">我是一些默认值,当使用者没有传递具体结构时,我会出现1</slot>
    <slot name="footer">我是一些默认值,当使用者没有传递具体结构时,我会出现2</slot>
  </div>
</template>


<script>
export default {
/* 组件名 */
  name: 'Category',
/* mixin(混入)  */
  mixins: [],
/* 配置声明子组件  */
  components: {},
/* 组件间数据、方法传值接收区  */
  props: [ 'title'],
/* 数据对象:数据赋值声明  */
  data () {
    return {

    }
  },
/* 计算属性:计算区  */
  computed: {},
/* 检测区  */
  watch: {},
/*   */
  created () {},
/*  挂载区 */
  mounted () {},
/*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">

.category{
    background-color: skyblue;
    width:200px;
    height:300px;
}
h3{
    text-align:center;
    background-color: orange ;
}

</style>







五:作用域插槽(slot-scope /scope)


1:看界面效果

Vue 中的 slot 插槽_插槽_07


2:代码结构

Vue 中的 slot 插槽_数据_08


3:代码内容


3.1:vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  pages:{
    index:{
      // 入口
      entry:'src/main.js',
    },
  },
  //配置vue脚手架的代理服务器:开启代理服务器  此处代理服务器默认与 该脚手架启动的模拟的前端服务器 端口相同:8080
  // 方式一
  /*
   devServer:{
     proxy:'http://localhost:5000/'
  },
 */
  // 方式二 
   devServer:{
      proxy:{
           //  '/api': 请求前缀 
          '/api':{
                    target:'http://localhost:5000/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/api':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  } ,
           //  '/api': 请求前缀 
          '/demo':{
                    target:'http://localhost:5001/',
                    // 将请求过来的url信息里的 请求前缀  格式化去除掉
                    pathRewrite:{'^/demo':''},
                    // ws:true,  //用于支持 websocket
                    // chageOrigin:true  // 用于控制请求头中的host值
                  }
      }
   },
   transpileDependencies: true,
   lintOnSave:false, /*关闭语法检查*/


})

3.2:main.js

//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'

// 引入 vue插件: vue-recource
import vueResource from 'vue-resource'

//关闭Vue生产提示
Vue.config.productionTip=false;

// 使用插件
Vue.use(vueResource);

// 创建Vm
const vm = new Vue(  {
        el:'#app',
        render: (h) => h(App),
        //添加全局事件总线对象
        beforeCreate(){
             Vue.prototype.$bus=this;
        }
   });

3.3:App.vue

<template>
  <div class="container">
    <Category title="游戏"   >
       <template  scope="Praram">  <!-- Praram 参数名命名随意 -->
            <ul >
              <li  v-for="(g,index) in Praram.slotPraram"  :key ="index">{{g}}</li>
            </ul>
       </template>
    </Category>

   <Category title="游戏"   >
        <template  scope="Praram">  <!-- Praram 参数名命名随意 -->
          <ol >
              <li style="color:red" v-for="(g,index) in  Praram.slotPraram"  :key ="index">{{g}}</li>
          </ol>
        </template>
    </Category>

    <Category title="游戏"   >
      <template  scope="{slotPraram}">  <!-- 支持结构赋值 旧的Api写法: scope-->
          <h4  v-for="(g,index) in  slotPraram"  :key ="index">{{g}}</h4>
      </template>
    </Category>
    <Category title="游戏"   >
      <template  slot-scope="{slotPraram}">  <!-- 支持结构赋值 新的api 写法:slot-scope-->
          <h4  v-for="(g,index) in  slotPraram"  :key ="index">{{g}}</h4>
      </template>
    </Category>
</div>
</template>


<script>
import Category from './components/Category.vue'


export default {
  /* 组件名 */
  name: 'App',
  /* mixin(混入)  */
  mixins: [],
  /* 配置声明子组件  */
  components: {Category},
  /* 组件间数据、方法传值接收区  */
  props: [],
  /* 数据对象:数据赋值声明  */
  data() {
    return {

    }
  },
  /* 计算属性:计算区  */
  computed: {},
  /* 检测区  */
  watch: {},
  /*   */
  created() { },
  /*  挂载区 */
  mounted() { },
  /*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">
    .container,.foot{
      display:flex;/* div 浮动 */
      justify-content: space-around; /* 主轴对齐 */
    }
    img{
      width:100%;
    }
    h4{
      text-align:center;
    }
    video{
       width:100%;
    }
</style>

3.4 :Category.vue

<template>
  <div class="category">
    <h3>{{title}}分类</h3>
      <!-- 定义一个插槽(挖个坑,等着组件的使用者进行填充) -->
      <slot  :slotPraram ="games"> 我是一些默认内容。</slot>  <!--  :slotPraram ="games": 将插槽vue里的数据传递到引用者的界面-->
  </div>
</template>


<script>
export default {
/* 组件名 */
  name: 'Category',
/* mixin(混入)  */
  mixins: [],
/* 配置声明子组件  */
  components: {},
/* 组件间数据、方法传值接收区  */
  props: [ 'title'],
/* 数据对象:数据赋值声明  */
  data () {
    return {
      games:['梦幻西游','大话西游','征途2','传奇'],

    }
  },
/* 计算属性:计算区  */
  computed: {},
/* 检测区  */
  watch: {},
/*   */
  created () {},
/*  挂载区 */
  mounted () {},
/*  方法区 */
  methods: {}
}
</script>


<style scoped lang="css">

.category{
    background-color: skyblue;
    width:200px;
    height:300px;
}
h3{
    text-align:center;
    background-color: orange ;
}

</style>









为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================

标签:slot,Category,Vue,插槽,App,vue,组件
From: https://blog.51cto.com/ios9/7493851

相关文章

  • Vuex
    目录一:Vue知识要点说明:二:示例一:Vue知识要点说明##Vuex###1.概念 在Vue中实现集中式状态(数据)管理的一个Vue插件,对vue应用中多个组件的共享状态进行集中式的管理(读/写),也是一种组件间通信的方式,且适用于任意组件间通信。Github地址:https://github.com/vuejs......
  • Vue响应式原理
    该随笔是根据b站小满zs的Vue3+vite+Ts+pinia+实战+源码+electron的视频学习写的,Vue3+vite+Ts+pinia+实战+源码+electron......
  • springboot vue uniapp 小说电子书阅读小程序APP源码
    开发环境及工具:大等于jdk1.8,大于mysql5.5,idea(eclipse),nodejs,vscode(webstorm),HBuilderX技术说明:springbootmybatisvueelementuiuniapp代码注释齐全,没有多余代码,适合学习(毕设),二次开发,包含论文技术相关文档。功能介绍:用户端:登录注册首页显示搜索小说,轮播图,最新发布小说(可带推荐算......
  • vue3-路由遇到的问题
    在Vue3中,使用VueRouter来管理应用程序的导航和路由。下面是VueRouter的一些常见使用方法:通过npm或yarn安装VueRouter:npminstallvue-router或yarnaddvue-router在主文件(通常是main.js)中导入VueRouter并创建一个实例:import{createApp}from'vue'importrouterfrom'......
  • vue中elementui el-input绑定的值如何过滤掉输入的空格?
    在vue中可以在@input事件中使用Trim函数来去掉前后两端空格,再使用replace方法来删除中间空格,此时的值删除所有空格,用户输入值中的空格就会被过滤掉了。<template> <div> <el-inputv-model="searchValue"@input="handleInput"></el-input></div></template><scrip......
  • Vue进阶(幺柒肆):鼠标、键盘事件
    (文章目录)一、前言在项目开发过程中,需要根据鼠标事件进行相应处理。现予以梳理。鼠标事件如下所示:点击事件:@click//单击@dblclick//双击@mousedown//按下@mouseup//抬起@contextmenu//鼠标右键悬浮事件及触发顺序:@mouseover//划过@mouseenter//进入@mouse......
  • 不再困惑:一文读懂Vue2与Vue3的主要差异
    Vue3相对于Vue2有很多改进和新特性。以下是一些主要的区别:性能更好:Vue3的性能比Vue2更好,因为它使用了更少的代码和更高效的算法。例如,Vue3使用Proxy代替了Object.defineProperty来监听数据变化,这使得Vue3的性能更高。组合式API:Vue3引入了组合式API,这是一种新的编写组件逻辑的方式。......
  • Vue3开发环境搭建全攻略:Vite的详细介绍
    Vite简介Vite这个单词是一个法语单词,意思就是轻快的意思。它和我们以前使用Vue-cli的作用基本相同,都是项目初始化构建工具,相当于Vue项目构建的第二代产品,当然它也包含了项目的编译功能。需要注意一下Vite的生产环境下打包是通过Rollup来完成的。Vite特性介绍Vite主打特点就是轻快冷......
  • Vue学习五:自定义指令、插槽
    一、自定义指令自定义指令:自己定义的指令,可以封装一些dom操作,扩展额外功能全局注册语法Vue.directive('指令名',{"inserted"(el){//可以对el标签,扩展额外功能}})ViewCode局部注册语法directives:{"指令名":{"inserted"(el){......
  • Vue-模板语法
    一、模板语法 插值语法最后都渲染成了字符串html:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title><scriptsrc="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jque......