鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ vue jsonp插件回調(diào)函數(shù)該如何定義

vue jsonp插件回調(diào)函數(shù)該如何定義

用jsonp插件調(diào)用數(shù)據(jù),已經(jīng)成功返回數(shù)據(jù),但一直提示回調(diào)函數(shù)未定義,可是我的jsonpCallback已經(jīng)定義了
圖片描述

import jsonp from "jsonp"

.......

var url = API + "?location=" + LOCATION + "&" + str + "&callback=jsonpCallback";
          
          var jsonpCallback = function(data) {
            var weather = data.results[0];
            var text = [];
            text.push("位置:" + weather.location.path);
            text.push("天氣:" + weather.now.text);
            text.push("溫度:" + weather.now.temperature + "℃");
            text.push("更新時間:" + weather.last_update);
            return text;
          }

            var param = {
                param : "jsonpCallback"
            }
            
            jsonp(url, param , function (err, data) {
              if (err) {
                console.error(err.message);
              } else {
                _this.xzWeatherInfo = jsonpCallback(data);
              }
            });
回答
編輯回答
枕頭人

var jsonpCallback =
改成
window.jsonpCallback

2018年8月28日 05:03