每天一点点之 taro 框架开发 - taro调用组件传值
1.调用组件
组件文件
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
export default class Dialog extends Component {
render () {
return (
<View className='index'>
我是弹窗组件
</View>
)
}
}
调用
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import Dialog from './dialog'
export default class TestDialog extends Component {
render () {
return (
<View className='index'>
<View>TestDialog</View>
<Dialog></Dialog>
</View>
)
}
}
2.向组件传值
组件
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
export default class Dialog extends Component {
render () {
return (
<View className='index'>
我是弹窗组件
{
this.props.children
}
</View>
)
}
}
调用
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button, Image } from '@tarojs/components'
import Dialog from './dialog'
export default class TestDialog extends Component {
render () {
return (
<View className='index'>
{/* TestDialog */}
<Dialog>
<Text>我是test传入的</Text>
</Dialog>
<Dialog>
<Image src={require('../../lib/img/二哈.jpg')}/>
</Dialog>
<Dialog>
<Button>按钮</Button>
</Dialog>
</View>
)
}
}
注意:在组件中的 this.props.children 是只读的,不能进行更改
3.向组件传递多个值
由于组件接收的值不能更改,那么如果想要在组件接收多个值,就会出现问题,针对这种情况方案如下:
在调用页面给组件名定义属性,在组件通过 this.props.myText 来接收值,代码如下:
组件
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
export default class Dialog extends Component {
render () {
return (
<View className='index'>
我是弹窗组件
{ this.props.myText }
{
this.props.children
}
</View>
)
}
}
调用
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button, Image } from '@tarojs/components'
import Dialog from './dialog'
export default class TestDialog extends Component {
render () {
return (
<View className='index'>
{/* TestDialog */}
<Dialog myText={<Text>我是myText传入的</Text>}>
<Text>我是test传入的</Text>
</Dialog>
<Dialog>
<Image src={require('../../lib/img/二哈.jpg')}/>
</Dialog>
<Dialog>
<Button>按钮</Button>
</Dialog>
</View>
)
}
}
每天一点点之 taro 框架开发 - taro调用组件传值的更多相关文章
- 每天一点点之 taro 框架开发 - taro静态资源引入
1.说明: taro中客园自由的引用静态资源,不需要安装任何的loader 引用样式文件 通过ES6的import引入 2.引用js文件 import { functionName } from '. ...
- 每天一点点之 taro 框架开发 - taro路由及传参
1.路由 taro的路由是自带的,不需要我们额外配置,只需要我们在app.js下config中配置pages即可 class App extends Component { config = { pa ...
- 每天一点点之vue框架开发 - 引入Jquery
1. 安装jquery npm install jquery --save-dev 2.在build/webpack.base.conf.js中添加如下内容 var webpack = require ...
- 每天一点点之vue框架开发 - 使用vue-router路由
1.安装路由(安装过的跳过此步) // 进入项目根目录 cd frontend // 安装 npm install vue-router --save-dev 2.在入口文件main.js中引入路由 ...
- 手把手教你使用Vue/React/Angular三大框架开发Pagination分页组件
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...
- 【WePY小程序框架实战三】-组件传值
[WePY小程序框架实战一]-创建项目 [WePY小程序框架实战二]-页面结构 父子组件传值 静态传值 静态传值为父组件向子组件传递常量数据,因此只能传递String字符串类型. 父组件 (paren ...
- 每天一点点之 taro 框架开发 - 事件处理与样式表
1.方法调用 state = { name:'张三' } test(){ this.state.name } <button onClick={ this.test.bind(this) } / ...
- 每天一点点之vue框架开发 - vue坑-This relative module was not found
94% asset optimization ERROR Failed to compile with 1 errors This relative module was not found: * . ...
- 每天一点点之vue框架开发 - @click-native-prevent
1.在封装好的组件上使用,所以要加上.native才能click 2.prevent就相当于..event.preventDefault() 所以@click.native.prevent是用来阻止默 ...
随机推荐
- 契约精神、尊重规则、SOP,对制造业来说是蜜糖还是毒药?
契约精神.尊重规则.执行SOP,这些词儿都天然带有光环,也有很多相关的好故事,全球范围内的企业家都对其推崇备至,摆出一副虔诚教徒的模样,事实上,缺乏契约精神.不遵守规则比之缺乏资本.丢掉订单更加不可接 ...
- 十六、myeclipse导入别人项目报错java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServle异常
问题原因:java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addServle异常 我是把别人的源码项目直接导 ...
- linux打包解压包(.tar .gz .tar.gz .zip)
01-.tar格式 解包:[*******]$ tar xvf FileName.tar 打包:[*******]$ tar cvf FileName.tar DirName(注:tar是打包,不是压 ...
- android:showAsAction
在res/layout/menu文件夹下,放置login.xml: <menu xmlns:android="http://schemas.android.com/apk/res/an ...
- 深入解读EOS源代码之——区块链内核
EOS进入大众视野并且受到热议已经有一段时间了,各种热捧和争议过后,是时候让我们静下来搞清楚EOS到底是一个什么样的产品.本文从技术角度深入的分析EOS底层设计,从源代码入手,一层层揭开EOS区块链底 ...
- C++编程学习(十二) STL
一.简介 标准模板库STL,是一组模板类和函数.提供了: 1.容器.用于存储信息. 2.迭代器.用于访问容器中的信息. 3.算法.操作容器内容. 1.容器 STL有两种类型的容器类: (1)顺序容器 ...
- mysql日常小总结(其实就今天)
联表查询: SELECT t1.user_Name FROM t_user AS t1 , t_comment AS t2 WHERE t2.user_id=t1.id 结果如图: 加上GRO ...
- PowerShell中执行.net类库
Powershell脚本一个比较强大的功能是可以直接调用.net类库(ps core能调用.net core类库),除了调用系统类库外,也可以调用自己编写的类库,从而扩充我们脚本的功能.本文这里简单的 ...
- 解决使用xampp无法通过ip访问的问题
本地能通过127.0.0.1或者localhost访问,无法通过外网地址访问: win解决防火墙问题: 1.进入控制面板 -> 系统和安全 -> 2.window防火墙 - 允许其他程序通 ...
- 阿里云安装配置nginx
一.简介 Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.它最常的用途是提供反向代理服务. 二 .安装 1.准备工作 Nginx ...