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调用组件传值的更多相关文章

  1. 每天一点点之 taro 框架开发 - taro静态资源引入

    1.说明: taro中客园自由的引用静态资源,不需要安装任何的loader 引用样式文件 通过ES6的import引入 2.引用js文件 import { functionName } from '. ...

  2. 每天一点点之 taro 框架开发 - taro路由及传参

    1.路由 taro的路由是自带的,不需要我们额外配置,只需要我们在app.js下config中配置pages即可 class App extends Component { config = { pa ...

  3. 每天一点点之vue框架开发 - 引入Jquery

    1. 安装jquery npm install jquery --save-dev 2.在build/webpack.base.conf.js中添加如下内容 var webpack = require ...

  4. 每天一点点之vue框架开发 - 使用vue-router路由

    1.安装路由(安装过的跳过此步) // 进入项目根目录 cd frontend // 安装 npm install vue-router --save-dev 2.在入口文件main.js中引入路由 ...

  5. 手把手教你使用Vue/React/Angular三大框架开发Pagination分页组件

    DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...

  6. 【WePY小程序框架实战三】-组件传值

    [WePY小程序框架实战一]-创建项目 [WePY小程序框架实战二]-页面结构 父子组件传值 静态传值 静态传值为父组件向子组件传递常量数据,因此只能传递String字符串类型. 父组件 (paren ...

  7. 每天一点点之 taro 框架开发 - 事件处理与样式表

    1.方法调用 state = { name:'张三' } test(){ this.state.name } <button onClick={ this.test.bind(this) } / ...

  8. 每天一点点之vue框架开发 - vue坑-This relative module was not found

    94% asset optimization ERROR Failed to compile with 1 errors This relative module was not found: * . ...

  9. 每天一点点之vue框架开发 - @click-native-prevent

    1.在封装好的组件上使用,所以要加上.native才能click 2.prevent就相当于..event.preventDefault() 所以@click.native.prevent是用来阻止默 ...

随机推荐

  1. Linux CentOS7 VMware linux和windows互传文件、用户配置文件和密码配置文件、用户组管理、用户管理

    一. linux和windows互传文件 X-shell.Securecrt远程终端,与Windows之间互传文件. 安装一个工具lrzsz [root@davery ~]# yum install ...

  2. linux环境下安装solr

    1.上传并解压solr文件 2.将solr解压缩包的dist/solr-4.10.3.war包部署到tomcat下.并改名为solr.war 3.解压war包(启动tomcat后会自动解压war包) ...

  3. 「CF741D」Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths

    传送门 Luogu 解题思路 考虑把22个字符状压下来,易知合法情况就是状态中之多有一个1,这个可以暴力一点判断23次. 然后后就是 dsu on the tree 了. 细节注意事项 咕咕咕 参考代 ...

  4. 浅析 URL

    浅析 URL 参考于维基百科 URL => Uniform Resource Locator : 统一资源定位符 统一资源定位符的标准格式如下: [协议类型]://[服务器地址]:[端口号]/[ ...

  5. vs2010编译C++ 栈的使用

    // CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  6. Docker基本使用运行ngix镜像

    docker pull 项目名 会从docker默认的仓库去拉去项目,如果是docker pull 项目名 地址 会从给定地址拉去镜像 docker run image名字  运行镜像 docker架 ...

  7. Day6-T1

    原题目 Describe:模拟大水题 code: #include<bits/stdc++.h> #define INF 214748364 #define eps 1e-9 #defin ...

  8. Java笔记--泛型

    1.泛型解决元素存储的安全性问题:解决获取数据元素时,需要类型强转的问题. --泛型的核心思想:把一个集合中的内容限制为一个特定的数据类型. 2.泛型的使用 1)在集合中使用 2)自定义泛型类.泛型接 ...

  9. Koa原理和封装

    相关文章 最基础 实现一个简单的koa2框架 实现一个简版koa koa实践及其手撸 Koa源码只有4个js文件 application.js:简单封装http.createServer()并整合co ...

  10. Spring的AOP开发(基于AspectJ的XML方式)

    Spring的AOP的简介: AOP思想最早是由AOP联盟组织提出的.Spring是使用这种思想最好的框架 Spring的AOP有自己实现的方式(非常繁琐). Aspect是一个AOP的框架, Spr ...