02 Taro頁面編寫和傳值

2021-10-06 04:22:47 字數 1778 閱讀 4791

上回說到taro打造hello-world應用。廢話不多說,直接上肉菜

export default class index extends component 

state =

render () = this.state

return (

)}}

mkdir -p src/components/child

cd src/components/child

touch index.jsx

編寫元件,**如下

import taro,  from '@tarojs/taro'

import proptypes from 'prop-types'

import from '@tarojs/components'

export default class child extends component

defaultprops =

render () = this.props

return (

我是肉菜中的

)}}

在主頁面index中引入

import child from "../../components/child";
render方法中即可運用

render ()  = this.state

return (

)}

cd tarodemo

taro create --name next // 建立next頁面

pages: [

'pages/index/index',

'pages/next/next'

]

在主頁面button上繫結跳轉事件

gonext() )

}

在next頁面接收引數

componentwillmount () 

const = this.$router.params

this.setstate()

}

const params = 

const res = await taro.request(params)

整合dva開發體驗更好,參考基於taro + dva構建的時裝衣櫥(電商實戰專案)

適配問題

taro以750px作為換算尺寸標準,尺寸單位使用px,缺省會進行轉換rpx/rem。如果你希望部分px單位不被轉換成rpx或者rem,將px寫成px或px

盡量避免在 componentdidmount 中呼叫 this.setstate,可在 willmount 中處理

你問為啥??因為在componentdidmount中呼叫this.setstate會導致觸發更新

不要在呼叫 this.setstate 時使用 this.state,會導致一些錯誤

多端元件

// 引用不變,編譯會自動識別

import child from '../../components/child'

tarodemo 專案位址

父子頁面傳值和子兄弟頁面傳值

前言 我是用的layer彈出框整的layer父子頁面 父 子 子 父 子彈窗給父頁面元素賦值 parent.parentinput val 這是從彈窗傳遞過來的資料 子彈窗呼叫父頁面方法 window.parent.childinvokermethod 子彈窗獲取父頁面元素的值 window.par...

關於jquery和子頁面向父頁面傳值

關於jquery和子頁面向父頁面傳值 剛接觸jquery 遇到問題了。想用jquery實現這樣乙個功能 例如當father頁面的乙個文字框 txtemployee 輸入控制項獲得焦點的時候。彈出乙個子頁面child.aspx child頁面中放的是乙個repeater控制項繫結的employee表中...

springmvc 頁面和後台傳值亂碼問題

最近在做乙個專案。用的springmvc框架,遇到了頁面傳值亂碼的問題。web.xml中已經統一配置了編碼過濾器。encodingfilter org.springframework.web.filter.characterencodingfilter encoding utf 8 forceenc...