首页 > 其他分享 >Vue重用组件

Vue重用组件

时间:2023-05-24 23:24:59浏览次数:31  
标签:Vue color 重用 1px rgba 组件 options 255

1、是什么?

这里主要是简单入门使用一下,复杂高阶的用法笔者暂时还没了解到

Vue重用组件是指可以被多个Vue实例重复使用的组件。这些组件可以包含自定义的状态和事件处理程序,并且可以在整个应用程序中共享。重用组件可以减少代码冗余,提高开发效率,并使代码更加模块化和可维护。
在Vue中,可以使用<component>标签来定义重用组件。

2、怎么玩?

组件页面1:MyButton.vue
友情提示:一般情况下组件都放在Component下

<template>
  <div class="button" :class="[type,size]">
    <!--标签内的文本动态替代插槽中的内容-->
    a
    <slot></slot>
    b
  </div>
</template>

<script>
const options = {
  name: 'MyButton',
  props: ['type', 'size']
}

export default options
</script>

<style scoped>
.button {
  display: inline-block;
  text-align: center;
  border-radius: 30px;
  margin: 5px;
  font: bold 12px/25px Arial, sans-serif;
  padding: 0 2px;
  text-shadow: 1px 1px 1px rgba(255, 255, 255, .22);
  box-shadow: 1px 1px 1px rgba(0, 0, 0, .29), inset 1px 1px 1px rgba(255, 255, 255, .44);
  transition: all 0.15s ease;
}

.button:hover {
  box-shadow: 1px 1px 1px rgba(0, 0, 0, .29), inset 1px 1px 2px rgba(0, 0, 0, .5);
}

.button:active {
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, .8);
}

.primary {
  background-color: #1d6ef9;
  color: #b5e3f1;
}

.danger {
  background-color: rgb(196, 50, 50);
  color: white;
}

.success {
  background-color: #a5cd4e;;
  color: #3e5706;
}

.small {
  width: 40px;
  height: 20px;
  font-size: 10px;
  line-height: 20px;
}

.middle {
  width: 50px;
  height: 25px;
  font-size: 14px;
  line-height: 25px;
}

.large {
  width: 60px;
  height: 30px;
  font-size: 18px;
  line-height: 30px;
}
</style>

props : 自定义组件属性
slot : 插槽,用户

组件页面2:MyTamplate.vue

<template>
  <div>
    <header>
      <h1>{{ message }}</h1>
    </header>
    <section>
      <p>{{ content }}</p>
    </section>
  </div>
</template>

<script>
const options = {
  name: "MyTemplate", // 指定组件名称
  data() {
    return {
      message: 'Hello World',
      content: 'This is my content.'
    }
  }
}
export default options
</script>

<style scoped>

</style>

使用自定义组件和自定义属性

<template>
  <div class="app-container">
    <h1>父组件</h1>
    <my-button type="primary" size="small">zs</my-button>
    <my-button type="danger" size="middle">ls</my-button>
    <my-button type="success" size="large">ww</my-button>

    <my-template></my-template>
  </div>
</template>

<script>
import MyButton from "@/components/MyButton";
import MyTemplate from "@/components/MyTemplate";
const options = {
  components: {
    MyButton,
    MyTemplate
  }
}
export default options
</script>

<style scoped> /*scoped : 只影响当前页面*/
</style>

3、效果

image

标签:Vue,color,重用,1px,rgba,组件,options,255
From: https://www.cnblogs.com/qbbit/p/17429840.html

相关文章

  • drf-视图组件
    目录一视图之两个视图基类1.1APIView使用APIView+序列化类+Response写接口1.2GenericAPIView[通用视图类]1.2.1主要的属性或方法1.2.2推导GenericAPIView的封装1.2.3写5个接口二5个视图扩展类2.1方法2.2自己封装2.3源码2.4具体使用,写5个接口三9个视图子类3.1介绍1)Cre......
  • drf-路由组件
    目录一路由Routers1.1什么情况下使用自动生成路由1.2自动生成路由使用方法1.3代码演示视图函数路由一路由Routers路由写法有多种-原始写法-映射的写法:path('books/',BookView.as_view({'get':'list','post':'create'}))-自动生成路由1.1什么情况下使用自动生成路......
  • java基于springboot+vue的书籍学习平台管理系统,学期学习论坛管理系统,附源码+数据库+lw
    1、项目介绍困扰管理层的许多问题当中,书籍学习将会是不敢忽视的一块。但是管理好书籍学习又面临很多麻烦需要解决,在工作琐碎,记录繁多的情况下将书籍学习的当前情况反应给相关部门决策,等等。在此情况下开发一款书籍学习平台,于是乎变得非常合乎时宜。经过网上调查和搜集数据,......
  • drf之登录功能,认证组件,权限组件,频率组件
    目录一、登录功能表模型视图类回顾路由二、认证组件认证组件使用步骤(固定用法)三、权限组件权限类的使用步骤四、频率组件频率类的使用步骤一、登录功能表模型classUserInfo(models.Model):name=models.CharField(max_length=32)password=models.CharField(max_......
  • django配置文件作用,drf 登录功能,drf认证组件,drf权限组件,drf频率组件
    django配置文件作用:    drf登录功能:view内:from.modelsimportUserInfo,UserTokenfromrest_framework.viewsetsimportViewSetimportuuidfromrest_framework.responseimportResponsefromrest_framework.decoratorsimportactionclassUser......
  • jmeter--定时器组件
    工作中,用jmeter写接口测试脚本、性能测试脚本时,通常也会用到定时器组件,一般用的比较多的还是固定定时器、同步定时器。对于其他的定时器了解的不是特别深,为了更系统更深入的学习jmeter工具和工具中的定时器组件,自己对一些经常使用的定时器组件进行了学习、探索,并记录了一些知识点......
  • Java Web三大组件之Filter过滤器
    JavaWeb三大组件(Servlet、Filter、Listener)1、Filter过滤器概念生活中的过滤器:净水器,空气净化器,大山里的土匪等JavaWeb中的过滤器:当浏览器访问服务器资源时,过滤器就会拦截浏览器发过来的请求,实现一些特别的功能作用:一般用于完成通用的操作,如登录验证,身份验证,统一字符编码和敏感字......
  • Vue中this.$nextTick()的理解与使用方法
    https://www.jb51.net/article/238332.htmhttps://blog.csdn.net/lzfengquan/article/details/118933093......
  • vs2019打包程序时添加自定义的系统必备组件
     若要创建引导程序包,必须创建产品清单产品清单 product.xml包清单 package.xml 将文件复制到引导程序文件夹位置C:\ProgramFiles(x86)\MicrosoftVisualStudio14.0\SDK\Bootstrapper\Packages文件夹下    ......
  • vue2实现高度过渡效果,函数式组件
    1.首先创建src下创建utils文件夹,创建transition.js文件封装过渡组件consttransitionStyle='0.3sheightease-in-out'constTransition={//进入前设置el元素的transition,高度0beforeEnter(el){el.style.transition=transitionStyleel.style.height......