首页 > 其他分享 >【快应用】父组件中如何设置子组件样式

【快应用】父组件中如何设置子组件样式

时间:2022-11-18 11:02:12浏览次数:70  
标签:flex 样式 items externalClasses childstyle 设置 组件

问题背景:

子组件被引用时,如果在父组件的布局效果不理想,需要去修改子组件对应的样式,是比较麻烦的,现在快应用在1100版本之后推出了externalClasses属性,可以将外部样式直接传给自定义组件,便于开发者调试。

使用方式:

1、子组件中声明传递的样式externalClasses: ['childstyle']和class=”childstyle”。

2、父组件里调用childstyle=”parentstyle。”

相关代码:

child.ux:

<template>

<div class="container">

<text class="txt" onclick="click">child button</text>

</div>

</template>

<style>

.container {

flex: 1;

flex-direction: column;

align-items: center;

}

</style>

<script>

import prompt from '@system.prompt';

export default {

externalClasses: ['txt'],

click() {

prompt.showToast({

message: 'this is child',

})

}

}

</script>

【快应用】父组件中如何设置子组件样式_开发者

parent.ux:

<import name="child" src="../New/child.ux"></import>

<template>

<div class="container">

<text class="txt">hello</text>

<child txt="parentxt"></child>

</div>

</template>

<style>

.container {

flex: 1;

flex-direction: column;

align-items: center;

}

.txt {

height: 150px;

width: 85%;

margin-bottom: 15px;

border: 1px solid #000000;

}

//父组件设置样式

.parentxt {

background-color: #00fa9a;

height: 150px;

width: 85%;

align-items: flex-start;

margin-bottom: 15px;

border-color: #9400D3;

border-width: 5px;

}

</style>

【快应用】父组件中如何设置子组件样式_自定义组件_02

运行截图:

【快应用】父组件中如何设置子组件样式_自定义组件_03

​欲了解更多更全技术文章,欢迎访问​​https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh​

标签:flex,样式,items,externalClasses,childstyle,设置,组件
From: https://blog.51cto.com/u_14772288/5867934

相关文章

  • React组件生命周期
     组件的生命周期  挂载:--------------- ......
  • win11不更新系统设置教程
    https://pcedu.pconline.com.cn/1501/15015038.html有用户不想更新自己的win11系统,但是不知道win11不更新系统如何设置,其实我们可以通过服务或者组策略来关闭更新。方法......
  • 四招教你样式化界面组件KendoReact,让应用程序主题更个性化
    KendoUI致力于新的开发,来满足不断变化的需求,通过React框架的KendoUIJavaScript封装来支持ReactJavascript框架。KendoUIforReact能够为客户提供更好的用户体验,并且......
  • 小程序富文本使用及样式修改
    1.使用<rich-textclass="textcontent":nodes="content"> </rich-text>使用类名可以直接修改文字样式 2.图片样式,使用正则添加类名textcontent.value=data.cont......
  • Android 服务组件
    定义服务是Android中实现程序后台运行的解决方案,不和用户交互而且要求长期运行的任务。多线程编程1.线程基本用法//继承Thread类classMyThreadextendsThread{......
  • vue elementui Switch组件添加开关样式
      /deep/.el-switch{   &::before{    content:'开';    display:none;    color:#fff;    z-index:1;  ......
  • vue组件通信6种方式总结(常问知识点)
    前言在Vue组件库开发过程中,Vue组件之间的通信一直是一个重要的话题,虽然官方推出的Vuex状态管理方案可以很好的解决组件之间的通信问题,但是在组件库内部使用Vuex往往会......
  • vue中兄弟组件方法互相调用 子组件调用子组件内的方法
    使用this.$refs方法,如果直接用无法调取到可以先打印出来看一下结构有时候需要加[0],如下:  两个子组件:<ads-banner-voteref="bannerVote"@openVote="openVote"/>/......
  • uniapp 手动引用组件
    1.官网下载https://ext.dcloud.net.cn/?cat1=2&cat2=21https://uniapp.dcloud.net.cn/component/2.把代码放到项目\components\uni-data-checkbox文件下3.在需要......
  • 使用路由元信息 全局控制显示隐藏路由组件
    1.在路由中配置自定义属性  2.在使用页面组件中 用$route.meta.show 是否为true判断组件显示或隐藏下面为例      3.示例 ......