首页 > 其他分享 >Vue 插槽slot 以及传递多个props

Vue 插槽slot 以及传递多个props

时间:2023-05-19 15:37:06浏览次数:29  
标签:slot Vue user2 firstName user1 lastName headerTwo export props


Vue 插槽slot 以及传递多个props_vue

<!--
 * @Descripttion: 插槽slot
 * @version: 
 * @Author: zhangfan
 * @email: [email protected]
 * @Date: 2020-05-14 09:08:01
 * @LastEditors: zhangfan
 * @LastEditTime: 2020-06-29 09:51:02
--> 
<template>
  <div class="topCon">
    <header-two>
      <template v-slot:header="slotProps">
        <h1>{{slotProps.user1.lastName}}</h1>
        <h1>{{slotProps.user2.lastName}}</h1>
      </template>
      <template v-slot:contenter>
         <p>A paragraph for the main content.</p>
         <p>And another one.</p>
      </template>
      <template v-slot:footer>
         <h2>Here's some contact info</h2>
      </template>
    </header-two>
  </div>
</template>

<script>
import headerTwo from "./headerTwo";
export default {
  name: "enterpriseDetail",
  components: {
    headerTwo
  },
  data() {
    return {
      
    };
  },
  computed: {},
  methods: {
    
  }
};
</script>

<style  scoped lang="less">
</style>
<!--
 * @Descripttion: 
 * @version: 
 * @Author: zhangfan
 * @email: [email protected]
 * @Date: 2020-06-28 15:24:08
 * @LastEditors: zhangfan
 * @LastEditTime: 2020-06-29 09:48:01
--> 
<template>
    <div class="headerTwo">
         <slot name="header" v-bind:user1="user1" v-bind:user2="user2">
           <h1>{{user1.firstName}}</h1>
           <h1>{{user2.firstName}}</h1>
         </slot>
         <slot name="contenter"></slot>
         <slot name="footer"></slot>
    </div>
</template>

<script>
export default {
  name: "headerTwo",
  data() {
    return {
      user1:{
          firstName  :"zhang",
          lastName :"san"
      },
      user2:{
          firstName  :"li",
          lastName :"si"
      }
    };
  },
 

};
</script>

<style  scoped lang="less">

</style>


标签:slot,Vue,user2,firstName,user1,lastName,headerTwo,export,props
From: https://blog.51cto.com/u_16120408/6312739

相关文章

  • Vue项目中使用mock
    概念:mock是一个模拟数据生成器,旨在帮助前端独立于后端进行开发,帮助编写单元测试。mock有如下功能:根据数据模板生成模板数据模拟ajax请求,生成请求数据基于html模板生成模拟数据安装mockjsnpminstallmockjs在src文件夹下新建mock文件夹5.在mock文件夹下新建index.js文件引入mock......
  • Vue中的动态组件
    1,定义:动态组件就是将几个组件放在一个挂载点下,这个挂载点就是标签,其需要绑定is属性,属性值为父组件中的变量,变量对应的值为要挂载的组件的组件名,然后根据父组件里某个变量来动态显示哪个,也可以都不显示,2,使用:<component>元素是vue里面的一个内置组件。在里面使用v-bind:is,可以实现......
  • Vue过滤器-filter
    1.局部定义过滤器<!--*@Descripttion:vue过滤器-filter*@version:*@Author:zhangfan*@email:[email protected]*@Date:2020-07-0309:10:28*@LastEditors:zhangfan*@LastEditTime:2020-07-1414:13:56--><template><divclass="......
  • Vue中的懒加载和按需加载
    1.懒加载懒加载也叫延迟加载,即在需要的时候进行加载,随用随载。vue项目打包的时候,如果项目比较庞大,那么将会打出一个很大的包,速度比较慢,这个时候可以考虑拆分,不要把所有的内容都打到一个包里面去。1.路由懒加载:我们平常使用router可能如下:importVuefrom'vue'importRouterfro......
  • Vue watch的immediate和deep
    1.immediateimmediate表示立即执行的意思,这样就是说不用等到value变化才会执行,默认的时候就会立刻执行一次。假设我们页面上有一个搜索框,每次输入内容的时候去请求一个接口,同时一进页面的时候需要调一下这个接口,我们可能一般这样写:<!--作者:zhangfan页面名称:watch的immediate和de......
  • 使用Vue脚手架工具快速搭建vue项目
    全局安装webpack使用npm(需要安装node环境)全局安装webpack,打开命令行工具输入:npminstallwebpack-g或者(npminstall-gwebpack),安装完成之后输入webpack-v,如下图,如果出现相应的版本号,则说明安装成功。全局安装vue-cli,在cmd中输入命令:(cnpminstall-g@vue/cli)用vue-cli来构建......
  • Vue生命周期钩子函数
    每个Vue实例创建时,都会经历一系列的初始化过程,同时也会调用相应的生命周期钩子,我们利用这些钩子,可以在合适的时机执行我们的业务逻辑。vue生命周期共分为四个阶段,八个基本钩子函数<script>exportdefault{data(){return{filter:"all",};},beforeCre......
  • less在vue项目中的全局变量设置
    1,使用全局变量的目的:sass或者less都提供变量设置,在需求切换主题的项目中使用less或者sass变量,只要修改变量值,编译后所有用到该变量的样式都会被修改为你想要的效果2,安装sass-resources-loadernpminstallsass-resources-loader--save-dev3,找到build文件夹下面的utils.jsreturn{......
  • Vue.js学习记录之在元素与template中使用v-if指令实例(转贴)
    语法比较简单,直接上代码:<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <title></title> <scriptsrc="https://cdn.bootcss.com/vue/2.2.2/vue.......
  • Vue路由router
    1、总体结构2、路由说明 ......