前端学习——Vue (Day5)

news2024/10/5 13:12:04

自定义指令

在这里插入图片描述

<template>
  <div>
    <h1>自定义指令</h1>
    <input v-focus ref="inp" type="text" />
  </div>
</template>

<script>
export default {
  // mounted(){
  //   this.$ref.inp.focus()
  // }

  // 2. 局部注册指令
  directives: {
    focus: {
      inserted(el) {
        // 可以对 el 标签,扩展额外功能
        el.focus();
      },
    },
  },
};
</script>

<style>
</style>
import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

// // 1. 全局注册指令
// Vue.directive('focus', {
//   // inserted会在指令所在的元素,被插入到页面中时被触发
//   "inserted" (el) {
//   // el指令所绑定的元素
//   el.focus()
//   }
//   })

new Vue({
  render: h => h(App),
}).$mount('#app')

在这里插入图片描述
在这里插入图片描述

自定义指令 - 指令的值

在这里插入图片描述

<template>
  <div>
    <h1 v-color="color1">指令的值1</h1>
    <h1 v-color="color2">指令的值2</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      color1:'red',
      color2:'green'
    };
  },
  directives: {
    // inserted提供的是元素被添加到页面中时的逻辑
    color: {
      inserted(el, binding) {
        el.style.color = binding.value;
      },
      // update指令的值修改的时候触发,提供值变化后,dom更新的逻辑
      update(el, binding) {
        el.style.color = binding.value;
      },
    },
  },
};
</script>

<style>
</style>

在这里插入图片描述
在这里插入图片描述

自定义指令 - v-loading 指令封装

在这里插入图片描述
在这里插入图片描述

<template>
  <div class="main">
    <div class="box" v-loading="isLoading">
      <ul>
        <li v-for="item in list" :key="item.id" class="news">
          <div class="left">
            <div class="title">{{ item.title }}</div>
            <div class="info">
              <span>{{ item.source }}</span>
              <span>{{ item.time }}</span>
            </div>
          </div>

          <div class="right">
            <img :src="item.img" alt="">
          </div>
        </li>
      </ul>
    </div>
    <div class="box2" v-loading="isLoading2"></div>
  </div>
</template>

<script>
// 安装axios =>  yarn add axios
import axios from 'axios'

// 接口地址:http://hmajax.itheima.net/api/news
// 请求方式:get
export default {
  data () {
    return {
      list: [],
      isLoading:true,
      isLoading2:true
    }
  },
  async created () {
    // 1. 发送请求获取数据
    const res = await axios.get('http://hmajax.itheima.net/api/news')
    
    setTimeout(() => {
      // 2. 更新到 list 中
      this.list = res.data.data
      this.isLoading = false
    }, 2000)
  },
  directives:{
    loading:{
      inserted(el,binding){
        binding.value ? el.classList.add('loading') : el.classList.remove('loading')
      },
      update(el,binding){
        binding.value ? el.classList.add('loading') : el.classList.remove('loading')
      }
      }
    }
  }
</script>

<style>
/* 伪类 - 蒙层效果 */
.loading:before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: #fff url('./loading.gif') no-repeat center;
}

.box2 {
  width: 400px;
  height: 400px;
  border: 2px solid #000;
  position: relative;
}

.box {
  width: 800px;
  min-height: 500px;
  border: 3px solid orange;
  border-radius: 5px;
  position: relative;
}
.news {
  display: flex;
  height: 120px;
  width: 600px;
  margin: 0 auto;
  padding: 20px 0;
  cursor: pointer;
}
.news .left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 10px;
}
.news .left .title {
  font-size: 20px;
}
.news .left .info {
  color: #999999;
}
.news .left .info span {
  margin-right: 20px;
}
.news .right {
  width: 160px;
  height: 120px;
}
.news .right img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>

在这里插入图片描述

在这里插入图片描述

插槽

默认插槽

在这里插入图片描述在这里插入图片描述

<template>
  <div>
    <!-- 2. 在使用组件时,在组建标签内填入内容 -->
    <MyDialog>
      <div>你确认要删除吗?</div>
    </MyDialog>
    <MyDialog>
      <p>你确认要退出吗?</p>
    </MyDialog>
  </div>
</template>

<script>
import MyDialog from "./components/MyDialog.vue"
export default {
  data() {
    return {}
  },
  components: {
    MyDialog,
  },
}
</script>

<style>
body {
  background-color: #b3b3b3;
}
</style>
<template>
  <div class="dialog">
    <div class="dialog-header">
      <h3>友情提示</h3>
      <span class="close">✖️</span>
    </div>

    <div class="dialog-content">
      <!-- 1. 在需要定制的位置,使用slot占位 -->
      <slot></slot>
    </div>
    <div class="dialog-footer">
      <button>取消</button>
      <button>确认</button>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {

    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.dialog {
  width: 470px;
  height: 230px;
  padding: 0 25px;
  background-color: #ffffff;
  margin: 40px auto;
  border-radius: 5px;
}
.dialog-header {
  height: 70px;
  line-height: 70px;
  font-size: 20px;
  border-bottom: 1px solid #ccc;
  position: relative;
}
.dialog-header .close {
  position: absolute;
  right: 0px;
  top: 0px;
  cursor: pointer;
}
.dialog-content {
  height: 80px;
  font-size: 18px;
  padding: 15px 0;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
.dialog-footer button {
  width: 65px;
  height: 35px;
  background-color: #ffffff;
  border: 1px solid #e1e3e9;
  cursor: pointer;
  outline: none;
  margin-left: 10px;
  border-radius: 3px;
}
.dialog-footer button:last-child {
  background-color: #007acc;
  color: #fff;
}
</style>

在这里插入图片描述在这里插入图片描述

后备内容(默认值)

在这里插入图片描述

<template>
  <div>
    <!-- 2. 在使用组件时,在组建标签内填入内容 -->
    <MyDialog>
      你确认要退出吗?
    </MyDialog>
    <MyDialog>
      
    </MyDialog>
  </div>
</template>

<script>
import MyDialog from "./components/MyDialog.vue"
export default {
  data() {
    return {}
  },
  components: {
    MyDialog,
  },
}
</script>

<style>
body {
  background-color: #b3b3b3;
}
</style>
<template>
  <div class="dialog">
    <div class="dialog-header">
      <h3>友情提示</h3>
      <span class="close">✖️</span>
    </div>

    <div class="dialog-content">
      <!-- 1. 在需要定制的位置,使用slot占位 -->
      <!-- 往slot标签内部,编写内容,可以作为后被内容 -->
      <slot>
        我是默认的文本内容
      </slot>
    </div>
    <div class="dialog-footer">
      <button>取消</button>
      <button>确认</button>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {

    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.dialog {
  width: 470px;
  height: 230px;
  padding: 0 25px;
  background-color: #ffffff;
  margin: 40px auto;
  border-radius: 5px;
}
.dialog-header {
  height: 70px;
  line-height: 70px;
  font-size: 20px;
  border-bottom: 1px solid #ccc;
  position: relative;
}
.dialog-header .close {
  position: absolute;
  right: 0px;
  top: 0px;
  cursor: pointer;
}
.dialog-content {
  height: 80px;
  font-size: 18px;
  padding: 15px 0;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
.dialog-footer button {
  width: 65px;
  height: 35px;
  background-color: #ffffff;
  border: 1px solid #e1e3e9;
  cursor: pointer;
  outline: none;
  margin-left: 10px;
  border-radius: 3px;
}
.dialog-footer button:last-child {
  background-color: #007acc;
  color: #fff;
}
</style>

在这里插入图片描述
在这里插入图片描述

具名插槽

在这里插入图片描述
在这里插入图片描述

<template>
  <div>
    <!-- 2. 在使用组件时,在组建标签内填入内容 -->
    <MyDialog>
      <template v-slot:head>
        <div>我是大标题</div>
        </template>
      <template v-slot:content>
        <div>我是内容</div>
      </template>
      <template v-slot:footer>
        <button>确认</button>
        <button>取消</button>
      </template>
    </MyDialog>
  </div>
</template>

<script>
import MyDialog from "./components/MyDialog.vue"
export default {
  data() {
    return {}
  },
  components: {
    MyDialog,
  },
}
</script>

<style>
body {
  background-color: #b3b3b3;
}
</style>
<template>
  <div class="dialog">
    <div class="dialog-header">
      <slot name="head"></slot>
    </div>

    <div class="dialog-content">
      <!-- 1. 在需要定制的>=位置,使用slot占位 -->
      <!-- 往slot标签内部,编写内容,可以作为后被内容 -->
      <slot name="content"></slot>
    </div>
    <div class="dialog-footer">
      <slot name="footer"></slot>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {

    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.dialog {
  width: 470px;
  height: 230px;
  padding: 0 25px;
  background-color: #ffffff;
  margin: 40px auto;
  border-radius: 5px;
}
.dialog-header {
  height: 70px;
  line-height: 70px;
  font-size: 20px;
  border-bottom: 1px solid #ccc;
  position: relative;
}
.dialog-header .close {
  position: absolute;
  right: 0px;
  top: 0px;
  cursor: pointer;
}
.dialog-content {
  height: 80px;
  font-size: 18px;
  padding: 15px 0;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
.dialog-footer button {
  width: 65px;
  height: 35px;
  background-color: #ffffff;
  border: 1px solid #e1e3e9;
  cursor: pointer;
  outline: none;
  margin-left: 10px;
  border-radius: 3px;
}
.dialog-footer button:last-child {
  background-color: #007acc;
  color: #fff;
}
</style>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

作用域插槽

在这里插入图片描述
在这里插入图片描述

<template>
  <div>
    <MyTable :data="list">
      <!-- 通过template #插槽名="变量名" 接收 -->
      <template #default="obj">
        <button @click="del(obj.row.id)">删除</button>
      </template>
    </MyTable>
    <MyTable :data="list2">
      <template #default="{row}">
        <button @click="show(row)">查看</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 },
      ],
    };
  },
  methods: {
    del(id) {
      this.list = this.list.filter((item) => item.id !== id);
    },
    show(row) {
      alert(`姓名:${row.name}; 年龄:${row.age}`)
    }
  },
  components: {
    MyTable,
  },
};
</script>

<template>
  <table class="my-table">
    <thead>
      <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>年纪</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="(item,index) in data" :key="item.id">
        <td>{{ index+1 }}</td>
        <td>{{ item.name }}</td>
        <td>{{ item.age }}</td>
        <td>
          <!-- 给slot标签,添加属性的方式传值 -->
          <slot :row="item" msg="测试文本"></slot>

          <!-- 将所有属性,添加到一个对象中 -->
          <!-- 
            {
              row:{ id:2,name:'孙大明',age:19},
              msg:'测试文本'
            }
           -->
        </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>

在这里插入图片描述
在这里插入图片描述

路由入门

单页应用程序: SPA - Single Page Application

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

路由的介绍

在这里插入图片描述
在这里插入图片描述

VueRouter 的 介绍

在这里插入图片描述
在这里插入图片描述

//main.js
import Vue from 'vue'
import App from './App.vue'

// 路由的使用步骤 5 + 2
// 5个基础步骤
// 1. 下载 v3.6.5
// 2. 引入
// 3. 安装注册 Vue.use(Vue插件)
// 4. 创建路由对象
// 5. 注入到new Vue中,建立关联

// 2个核心步骤
// 1. 建组件(views目录),配规则
// 2. 准备导航链接,配置路由出口(匹配的组件展示的位置) 
import Find from './views/Find'
import My from './views/My'
import Friend from './views/Friend'
import VueRouter from 'vue-router'
Vue.use(VueRouter) // VueRouter插件初始化

const router = new VueRouter({
  // routes 路由规则们
  // route  一条路由规则 { path: 路径, component: 组件 }
  routes: [
    { path: '/find', component: Find },
    { path: '/my', component: My },
    { path: '/friend', component: Friend },
  ]
})

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
  router
}).$mount('#app')

在这里插入图片描述
在这里插入图片描述

组件存放目录问题 (组件分类)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/796588.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

桥梁安全监测系统中数据采集上传用 什么?

背景 2023年7月6日凌晨时分&#xff0c;G5012恩广高速达万段230公里加80米处6号大桥部分桥面发生垮塌&#xff0c;导致造成2车受损后自燃&#xff0c;3人受轻伤。目前&#xff0c;四川省公安厅交通警察总队高速公路五支队十四大队民警已对现场进行双向管制。 作为世界第一桥梁…

亚马逊云科技纽约峰会官宣生成式AI产品策略升级

作为云计算领域的领导者和创新者&#xff0c;生成式AI&#xff08;Generative AI&#xff09;一直是亚马逊云科技持续关注和投入的主要方向。在今年4月&#xff0c;亚马逊云科技发布了以Amazon Bedrock为代表的生成式AI产品全家桶&#xff0c;正式入局该赛道并宣布了亚马逊云科…

进程信息查看脚本

一、shell 脚本 该脚本可以根据进程名和进程pid查询进程信息。 输出的进程信息包括&#xff1a;进程 PID、进程命令、进程所属用户、CPU占用率、内存占用率等 查询可选择模式&#xff1a;仅一次还是不限次。 #! /bin/bashprintProcessInfo(){P$1echo "------------------…

15 文本编辑器vim

15.1 建立文件命令 如果file.txt就是修改这个文件&#xff0c;如果不存在就是新建一个文件。 vim file.txt 使用vim建完文件后&#xff0c;会自动进入文件中。 15.2 切换模式 底部要是显示插入&#xff0c;是编辑模式&#xff1b; 按esc&#xff0c;底部要是空白的&#xff0…

NetCore 使用 Swashbuckle 搭建 SwaggerHub

什么是SwaggerHub? Hub 谓之 中心, 所以 SwaggerHub即swagger中心. 什么时候需要它? 通常, 公司都拥有多个服务, 例如商品服务, 订单服务, 用户服务, 等等, 每个服务都有自己的environment, endpoint, swagger schema. 然而这些信息都分散在各处, 如果能集中在一个地方展示…

自主AI代理:未来的生产力引擎

摘要 文章介绍了自主AI代理的概念&#xff0c;AI代理由AI驱动&#xff0c;能够自我创建、优先处理和完成任务。自主AI代理可以执行任何数量的任务&#xff0c;包括内容创建、个人助手、个人财务管理、研究和数据分析等。文章强调了知识、记忆和学习在构建成功的自主AI代理中的重…

任务与项目的巧妙运用:项目管理软件的有效实践方法

如果您不熟悉项目管理或以前依赖任务管理系统来管理您的项目&#xff0c;那么任务和项目之间的区别可能会令人困惑。任务和项目是项目管理软件中的主要构建块&#xff0c;使您能够跟踪和组织您的工作。 任务是需要在项目中完成的单个工作单元。项目是需要一起完成以实现单个结果…

Linux数据处理三剑客

目录&#xff1a; Linux 三剑客之 greplinux三剑客之awklinux三剑客之sedlinux三剑客与管道使用【实战】三剑客实战之nginx日志分析实战【实战】三剑客实战之性能、网络统计实战linux进阶命令linux环境配置Linux与Bash编程实战 1.Linux 三剑客之 grep 内容检索:&#xff08;…

高电压放大器ATA-2021B在无损检测领域中的应用

超声无损检测&#xff08;UltrasonicNondestructiveTesting&#xff0c;简称UT&#xff09;是一种常用的材料及构件内部缺陷检测技术。它利用超声波在材料中传播的特性&#xff0c;通过接收回波信号来检测材料内部的缺陷情况。超声无损检测具有精度高、快速、非破坏性等优点&am…

k8s Webhook 使用java springboot实现webhook 学习总结

k8s Webhook 使用java springboot实现webhook 学习总结 大纲 基础概念准入控制器&#xff08;Admission Controllers&#xff09;ValidatingWebhookConfiguration 与 MutatingWebhookConfiguration准入检查&#xff08;AdmissionReview&#xff09;使用Springboot实现k8s-Web…

【录用案例】2区SCI,仅14天见刊!

近日新增两本2区SCI录用&#xff0c;期刊表现质量优&#xff0c;均是隶属于世界前列的出版社&#xff0c;好刊版面紧俏&#xff0c;可放心投稿&#xff01;录用案例如下&#xff0c;可重点参考&#xff1a; 计算机科学类SCI&EI 【影响因子】IF&#xff08;2022&#xff0…

Microsoft todo 数据导出

文章目录 官方说明&#xff1a; https://support.microsoft.com/zh-cn/office/导出您的-microsoft-待办事项帐户-d286b243-affb-4db4-addc-162e16588943 由于 微软待办 会自动与 Outlook 中的任务同步&#xff0c;因此您可以从 Outlook 中导出所有列表和任务。 若要导出列表和…

Docker 安全 Docker HTTPS请求过程与配置

Docker 容器安全注意点 尽量别做的事 尽量不用 --privileged 运行容器&#xff08;授权容器root用户拥有宿主机的root权限&#xff09; 尽量不用 --network host 运行容器&#xff08;使用 host 网络模式共享宿主机的网络命名空间&#xff09; 尽量不在容器中运行 ssh 服务 尽…

11.对象

11.1什么是对象 ●对象(object) : JavaScript里的一种数据类型 ●可以理解为是一种无序的数据集合&#xff0c;注意数组是有序的数据集合 11.2对象的使用 1.对象的声明语法 &#xff08;1&#xff09;let对象名 {} &#xff08;2&#xff09;let对象名new Object() // {} …

vue实现flv格式视频播放

公司项目需要实现摄像头实时视频播放&#xff0c;flv格式的视频。先百度使用flv.js插件实现&#xff0c;但是两个摄像头一个能放一个不能放&#xff0c;没有找到原因。&#xff08;开始两个都能放&#xff0c;后端更改地址后不有一个不能放&#xff09;但是在另一个系统上是可以…

振弦采集仪及在线监测系统完整链条的岩土工程隧道安全监测

振弦采集仪及在线监测系统完整链条的岩土工程隧道安全监测 近年来&#xff0c;随着城市化的不断推进和基础设施建设的不断发展&#xff0c;隧道建设也日益成为城市交通发展的必需品。然而&#xff0c;隧道建设中存在着一定的安全隐患&#xff0c;如地质灾害、地下水涌流等&…

Python(四十三)else语句

❤️ 专栏简介&#xff1a;本专栏记录了我个人从零开始学习Python编程的过程。在这个专栏中&#xff0c;我将分享我在学习Python的过程中的学习笔记、学习路线以及各个知识点。 ☀️ 专栏适用人群 &#xff1a;本专栏适用于希望学习Python编程的初学者和有一定编程基础的人。无…

实用人工智能 2.0,在线“学习、探索和构建”ML 模型

人工智能爱好者过去需要在一个好的GPU上投资数千美元才能“动手”进行机器学习&#xff0c;但现在一个简单的网络浏览器就足够了。总部位于硅谷的非营利组织PracticalAI最近发布了“PracticalAI2.0”&#xff0c;该平台包括TensorFlow 2.0Keras中的说明性机器学习课程&#xff…

吉客云对接打通金蝶云星空分页查询出库单接口与其他出库新增接口

吉客云对接打通金蝶云星空分页查询出库单接口与其他出库新增接口 对接系统吉客云 杭州吉客云网络技术有限公司是经国家认定的高新技术企业&#xff0c;是国内领先的SaaSERP软件服务商&#xff0c;致力于为企业提供安全稳定、高可用性和高扩展性的一站式数字化解决方案。 接通系…

如何全面评价国内的低代码开发平台 (apaas)?

低代码开发平台是无需编码&#xff08;0代码&#xff09;或通过少量代码就可以快速生成应用程序的开发平台。 通过可视化进行应用程序开发的方法&#xff08;参考可视编程语言&#xff09;&#xff0c;使具有不同经验水平的开发人员可以通过图形化的用户界面&#xff0c;使用拖…