首页 > 其他分享 >作用域插槽

作用域插槽

时间:2023-11-12 17:56:16浏览次数:25  
标签:name 作用域 插槽 border age table my id

<template>
  <div>
    <MyTable :data="list">
      <template #default="obj">
        <button @click="del(obj.row.id)">删除</button>
      </template>
    </MyTable>
    <MyTable :data="list">
      <template #default="obj">
        <button @click="show(obj.row.id)">查看</button>
      </template>
    </MyTable>
  </div>
</template>

<script>

import MyTable from './components/MyTable.vue'
export default {
  data () {
    return {
      list: [
        { id: 1, name: '张小花', age: 18 },
        { id: 2, name: '孙大明', age: 19 },
        { id: 3, name: '刘德忠', age: 17 },
      ],
      list2: [
        { id: 1, name: '赵小云', age: 18 },
        { id: 2, name: '刘蓓蓓', age: 19 },
        { id: 3, name: '姜肖泰', age: 17 },
      ]
    }
  },
  components: {
    MyTable
  },
  methods:{
    del(id){
      this.list=this.list.filter(item => item.id!=id)
    },
    show(id){
      console.log(this.list2.find(item=>item.id==id).id);
    }
  }
}
</script>
<template>
  <table class="my-table">
    <thead>
      <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>年纪</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody v-for="(item,index) in data" :key="item.id">
      <tr>
        <td>{{index+1}}</td>
        <td>{{item.name}}</td>
        <td>{{item.age}}</td>
        <td>
          <slot :row="item" msg="测试"></slot>
        </td>
      </tr>
    </tbody>
  </table>
</template>

<script>
export default {
  props: {
    data: Array,
  },
}
</script>

<style scoped>
.my-table {
  width: 450px;
  text-align: center;
  border: 1px solid #ccc;
  font-size: 24px;
  margin: 30px auto;
}
.my-table thead {
  background-color: #1f74ff;
  color: #fff;
}
.my-table thead th {
  font-weight: normal;
}
.my-table thead tr {
  line-height: 40px;
}
.my-table th,
.my-table td {
  border-bottom: 1px solid #ccc;
  border-right: 1px solid #ccc;
}
.my-table td:last-child {
  border-right: none;
}
.my-table tr:last-child td {
  border-bottom: none;
}
.my-table button {
  width: 65px;
  height: 35px;
  font-size: 18px;
  border: 1px solid #ccc;
  outline: none;
  border-radius: 3px;
  cursor: pointer;
  background-color: #ffffff;
  margin-left: 5px;
}
</style>

 

标签:name,作用域,插槽,border,age,table,my,id
From: https://www.cnblogs.com/wllovelmbforever/p/17827321.html

相关文章

  • Vue中的插槽
    插槽-默认插槽作用:让组件内部的一些结构支持自定义需求:要在页面中显示一个对话框,封装成一个组件,但是组件的内容部分,不是写死的,希望能使用时自定义。插槽的基本语法组件内需要定制的结构部分,改用<slot></slot>占位使用组件时,在组件中传入结构替换slot,例如<组件名>xxxxxx</组......
  • 变量,常量,作用域,变量的命名规范
       ......
  • requestAnimationFrame虽然是异步函数,但是由于i是用let定义的,每一次都会生成一个块级
    以下代码执行后,console输出的信息是?for(leti=0;i<5;i++){requestAnimationFrame(()=>console.log(i));}01234requestAnimationFrame虽然是异步函数,但是由于i是用let定义的,每一次都会生成一个块级作用域,来把当前值和requestAnimationFrame放在这个作用域中......
  • let是es6中声明变量的方式,有自己的作用域块,可以放变量,所以let绑定for循环时,每个i都有
    for(leti=0;i<2;i++){setTimeout(function(){console.log(i)},100);}for(vari=0;i<2;i++){setTimeout(function(){console.log(i)},100);}问:控制台打印的结果是?0122①Js是单线程的,Settimeout是异步宏任务,所以代码执行遇到异步的,就......
  • 四个作用域九大内置对象
    九大对象:内置对象(又叫隐含对象,有9个内置对象):不需要预先声明就可以在脚本代码和表达式中随意使用out:javax.servlet.jsp.JspWriter类型,代表输出流的对象。作用域为page(页面执行期)request:javax.servlet.ServletRequest的子类型,此对象封装了由WEB浏览器或其它客户端生成地HTTP请求的......
  • vue-test4 -----插槽
    <template><!--<Mainclass="cccc"/><component-a/>--><slot-demo><template#header="slotProps"><p>插槽标题-{{slotProps.msg}}</p></template><template......
  • go--变量、常量、作用域
    变量变量可以通过变量名访问。Go语言变量名由字母、数字、下划线组成,其中首个字符不能为数字。声明变量的一般形式是使用var关键字:var变量名变量类型也可以一次声明多个变量var变量名1,变量名2变量类型packagemainimport"fmt"funcmain(){varastring=......
  • 组件多插槽的使用
    <BtnHandle:eventBtn="eventBtn"><templatev-for="(_,slotKey,slotIndex)in$slots":key="slotIndex"#[slotKey]="slotData">......
  • 作用域和闭包
    一、作用域var可以重复声明,重复声明时实际是跳过声明处理,继续执行赋值操作。宽松模式下,a=2如果找不到a的声明,会在全局声明一个a;严格模式下严格模式禁止自动或隐式地创建全局变量。functionfoo(a){console.log(a+b);b=a;}foo(2);//ReferenceError:bisnot......
  • Jemeter元件执行顺序及作用域
          ......