嘿,我正在寻求帮助。我在使用上下文 api 将数据从一个子组件传递到另一个子组件时遇到一些问题。但我得到了这个 typeError ,到目前为止我尝试了一些搜索,但运气不佳。如果有人不能指出我正确的方向,我将不胜感激!
谢谢
import { React, Component} from 'react';
export const MContext = React.createContext('');
class CurrencyProvider extends Component {
constructor() {
super()
this.state = {
setinputValue: (value) => this.setState({ inputValue: value })
}
}
render() {
return (
<MContext.Provider value={this.state}>
{this.props.children}
</MContext.Provider>)
}
}
export default CurrencyProvider;
Run Code Online (Sandbox Code Playgroud)
Dropdown.js
import { useQuery, gql } from "@apollo/client";
import { useState } from "react";
import './Dropdown.scss';
import { MContext } from "../CurrencyProvider";
const EXCHANGE_RATES = gql`
query GetExchangeRates { …Run Code Online (Sandbox Code Playgroud) 嘿家伙尝试反应,并在使用时遇到问题setState,我一直得到无法读取setState未定义错误的属性,我不知道如何解决它.我已经尝试在构造函数中使用bind,但仍然无法解决问题.
感谢您的输入.
import React from 'react';
class Products extends React.Component {
constructor(props) {
super(props)
this.state = {products:{}}
this.getItems = this.getItems.bind(this)
}
componentDidMount() {
this.getItems('http://lcboapi.com/products/300681').then(function(response){
console.log(response);
this.setState({products:response});
},function(error){
console.log('failed',error);
});
}
componentWillMount() {
}
getItems(url){
return new Promise(function (resolve,reject) {
var req = new XMLHttpRequest();
req.open('GET',url);
req.setRequestHeader('Authorization','Token Token');
req.onload = function(){
if(req.status == 200){
resolve(req.response);
}else{
reject(Error(req.statusText));
}
};
req.onerror = function(){
reject(Error("Error"));
};
req.send();
});
}
render() {
return (
<div>
hi
</div>
);
}
} …Run Code Online (Sandbox Code Playgroud) 嘿,我正在浏览 emberjs 教程,但我遇到了这个无法解决的问题。当我尝试从 store 调用 findAll 函数时,它会抛出类型错误并表示 findAll 不是函数。当我使用 this.get() 方法时,它说它是一个经典的 ember 对象方法,并且不能在辛烷类中使用。有人知道如何解决这个问题吗?
在此先感谢您的时间!
应用程序/路线/rental.js
import Route from '@ember/routing/route';
export default class RentalsRoute extends Route {
model() {
return this.store.findAll('rental');
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/rental.js
import Model, { attr } from '@ember-data/model';
export default class RentalModel extends Model {
@attr title;
@attr owner;
@attr city;
@attr propertyType;
@attr image;
@attr bedrooms;
@attr description;
}
Run Code Online (Sandbox Code Playgroud)
海市蜃楼/config.js
export default function () {
this.namespace = '/api';
this.get('/rentals', function () {
return {
data: [
{ …Run Code Online (Sandbox Code Playgroud) 想知道为什么我需要在数组长度上加4才能反向打印整个数组?
在我添加4之前它只是使用.length属性而且它只打印出6543.
提前致谢!
function reverseArray(array) {
var newArray =[];
for(var i = 0; i <= array.length+4; i++) {
newArray += array.pop(i);
}
return newArray;
}
var numbers = [1,2,3,4,5,6];
console.log(reverseArray(numbers));
Run Code Online (Sandbox Code Playgroud) javascript ×3
reactjs ×2
arrays ×1
ember-data ×1
ember.js ×1
react-hooks ×1
reversing ×1
this ×1