react实现轮播图,以及实现绑定组件。
绑定组件:
//
创建一个变量, 与某个组件绑定
fl = React.createRef();
在html中创建ref={this.fl},
在函数中操作:this.fl.current.scrollToIndex({index: this.current})
具体看以下代码
// rnc
import React, {
Component} from 'react';
import {
Dimensions, FlatList, Image, Text, View} from 'react-native';
const {
width, height} = Dimensions.get('screen');
const rpx = x => (width / 750) * x;
export default class App extends Component {
douyu = 'http://capi.douyucdn.cn/api/v1/live?limit=20&offset=0';
state = {
data: []};
componentDidMount() {
fetch(this.douyu)
.then(res => res.json())
.then(res => {
console.