我对ReactJS很新,并且已经学习了不到两个月,我试图重新创建我在网上看到的一个项目,并将其更新为ES6 https://github.com/perborgen/YourSecondReactProject/blob/master/finished_project.html。
问题是,我以前从未尝试过任何调用,比如Ajax,fetch等。所以当我开始这个时,我得到一个错误,我的ajax是未定义的,我很确定我可能有我的语法或格式错误,请帮助我并解释我的错误是什么以及如何解决它们。非常感谢你!
P.S。我没有iTunes帐户,所以我使用了Tmdb api。
这是我试图做的事情
Private Sub CommandButton1_Click()
Dim Wb1 As Workbook, Wb2 As Workbook
Set Wb1 = ThisWorkbook
Dim WS As Worksheet
Dim L As Long, X As Long
spath = "c:\attachments\"
sfile = Dir(spath & "*.xls*")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set WS = Sheets.Add(before:=Sheets(1))
L = 1
Do While sfile <> ""
Set Wb2 = Workbooks.Open(spath & sfile)
For X = 6 To Wb2.Sheets.Count
Wb1.Sheets(1).Cells(L, "B").Value = Wb2.Sheets("Daily_Revenue_Management").Range("C33").Value
Wb1.Sheets(1).Cells(L, "C").Value = Wb2.Sheets("Daily_Revenue_Management").Range("D3").Value
Wb1.Sheets(1).Cells(L, "D").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("D4").Value
Wb1.Sheets(1).Cells(L, "E").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("D5").Value
Wb1.Sheets(1).Cells(L, "F").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("D6").Value
Wb1.Sheets(1).Cells(L, "G").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("D7").Value
Wb1.Sheets(1).Cells(L, "H").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("D8").Value
Wb1.Sheets(1).Cells(L, "I").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("E4").Value
Wb1.Sheets(1).Cells(L, "J").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("E5").Value
Wb1.Sheets(1).Cells(L, "K").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("E6").Value
Wb1.Sheets(1).Cells(L, "L").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("E7").Value
Wb1.Sheets(1).Cells(L, "M").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("E8").Value
Wb1.Sheets(1).Cells(L, "N").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("G4").Value
Wb1.Sheets(1).Cells(L, "O").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("G5").Value
Wb1.Sheets(1).Cells(L, "P").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("G6").Value
Wb1.Sheets(1).Cells(L, "Q").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("G7").Value
Wb1.Sheets(1).Cells(L, "R").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("G8").Value
Wb1.Sheets(1).Cells(L, "S").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("H4").Value
Wb1.Sheets(1).Cells(L, "T").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("H5").Value
Wb1.Sheets(1).Cells(L, "U").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("H6").Value
Wb1.Sheets(1).Cells(L, "V").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("H7").Value
Wb1.Sheets(1).Cells(L, "W").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("H8").Value
Wb1.Sheets(1).Cells(L, "X").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("I4").Value
Wb1.Sheets(1).Cells(L, "Y").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("I5").Value
Wb1.Sheets(1).Cells(L, "Z").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("I6").Value
Wb1.Sheets(1).Cells(L, "AA").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("I7").Value
Wb1.Sheets(1).Cells(L, "AB").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("I8").Value
Wb1.Sheets(1).Cells(L, "AC").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("L4").Value
Wb1.Sheets(1).Cells(L, "AD").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("L5").Value
Wb1.Sheets(1).Cells(L, "AE").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("L6").Value
Wb1.Sheets(1).Cells(L, "AF").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("L7").Value
Wb1.Sheets(1).Cells(L, "AG").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("L8").Value
Wb1.Sheets(1).Cells(L, "AH").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("M4").Value
Wb1.Sheets(1).Cells(L, "AI").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("M5").Value
Wb1.Sheets(1).Cells(L, "AJ").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("M6").Value
Wb1.Sheets(1).Cells(L, "AK").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("M7").Value
Wb1.Sheets(1).Cells(L, "AL").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("M8").Value
Wb1.Sheets(1).Cells(L, "AM").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("N4").Value
Wb1.Sheets(1).Cells(L, "AN").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("N5").Value
Wb1.Sheets(1).Cells(L, "AO").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("N6").Value
Wb1.Sheets(1).Cells(L, "AP").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("N7").Value
Wb1.Sheets(1).Cells(L, "AQ").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("N8").Value
Wb1.Sheets(1).Cells(L, "AR").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("Q4").Value
Wb1.Sheets(1).Cells(L, "AS").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("Q5").Value
Wb1.Sheets(1).Cells(L, "AT").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("Q6").Value
Wb1.Sheets(1).Cells(L, "AU").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("Q7").Value
Wb1.Sheets(1).Cells(L, "AV").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("Q8").Value
Wb1.Sheets(1).Cells(L, "AW").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("R4").Value
Wb1.Sheets(1).Cells(L, "AX").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("R5").Value
Wb1.Sheets(1).Cells(L, "AY").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("R6").Value
Wb1.Sheets(1).Cells(L, "AZ").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("R7").Value
Wb1.Sheets(1).Cells(L, "BA").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("R8").Value
Wb1.Sheets(1).Cells(L, "BB").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("S4").Value
Wb1.Sheets(1).Cells(L, "BC").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("S5").Value
Wb1.Sheets(1).Cells(L, "BD").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("S6").Value
Wb1.Sheets(1).Cells(L, "BE").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("S7").Value
Wb1.Sheets(1).Cells(L, "BF").Value = Wb2.Sheets("Rolling 4month Snapshot").Range("S8").Value
L = L + 1
Next
Wb2.Close False
sfile = Dir()
Loop
ActiveWorkbook.Save
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
If L > 0 Then
End If
Sheets("Sheet1").Select
Range("B1:B1000").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("data").Visible = True
Sheets("data").Select
Range("B1").Select
ActiveSheet.Paste
Sheets("data").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Sheet1").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete
Sheets("Dashboard").Select
Range("A5").Select
ActiveCell.FormulaR1C1 = "Updated: " & Format(Date, "MM/DD/YYYY")
Range("A6").Select
UserForm1.Hide
End Sub
答案 0 :(得分:0)
要使用ajax功能,您需要安装jquery
。你可以运行
npm install -S jquery
安装它。之后,您需要在组件中导入它,如
import $ from 'jquery';
然后修改你的ajax调用,如
search = (URL) => {
$.ajax({
type: "GET",
dataType: 'jsonp',
url: URL,
success: function(response){
this.showResults(response);
}.bind(this);
});
}
然而,更好地利用其他库(如axios
或node-fetch
)专门用于进行API调用而不是使用Jquery,因为除了AJAX调用之外,它还具有更多功能你不需要。
从文档中获取的Axios get请求示例为
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});