小编Jam*_*ons的帖子

Vue和Axios CORS错误请求的资源上没有"Access-Control-Allow-Origin"标头

我目前收到上述错误,我正在使用Axios向外部API发出GET请求.在阅读了Mozilla文档后,做了大量的研究并尝试了不同的选择,我仍然没有任何好转.

我已经将代码剥离回基础:

axios.get('URL.com', {
        headers: {
          Access-Control-Allow-Origin: *
        },
        auth: {
          username: 'username',
          password: 'password'
        },
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
Run Code Online (Sandbox Code Playgroud)

我是否需要在标题中添加其他内容?

一切都通过Postman工作,所以一旦我能通过CORS问题,一切都会奏效.

javascript get cors vue.js axios

12
推荐指数
1
解决办法
3万
查看次数

将es6-promise polyfill导入Vue.js

我在旧版Android中加载包含axios的Vue组件时遇到问题。经过一些研究,它指出浏览器不支持Promises,因此不支持polyfill。

我已经安装并导入了polyfill,但是仍然有问题。

import Promise from 'es6-promise';
Run Code Online (Sandbox Code Playgroud)

以上正确吗?还是还有其他问题?

javascript android polyfills es6-promise vuejs2

5
推荐指数
1
解决办法
4031
查看次数

使用 React Native 和 Laravel 后端验证 Pusher

我正在尝试使用以下 React Native 脚本对私人广播进行身份验证。

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Pusher from 'pusher-js/react-native';

export default class App extends React.Component {
  componentWillMount() {
    Pusher.logToConsole = true;
    var pusher = new Pusher('*********', {
      authEndpoint: 'http://app.pgm/api/authtest',
      cluster: 'eu',
      encrypted: true
    });

    const channel = pusher.subscribe('private-chat-1');

  }
Run Code Online (Sandbox Code Playgroud)

上面的内容被发布到下面的函数中,下面的函数在从 Postman 测试时返回一个 auth 令牌。但是,当我通过 React Native 运行该应用程序时,我得到以下响应。

  public function pusher(Request $request){
        $pusher = new Pusher(config('broadcasting.connections.pusher.key'), config('broadcasting.connections.pusher.secret'), config('broadcasting.connections.pusher.app_id'));

        echo $pusher->socket_auth($request->channel_name, $request->socket_id);
  }
Run Code Online (Sandbox Code Playgroud)

[exp] Pusher : 无法检索身份验证信息。0客户端必须经过身份验证才能加入私有或在线通道。请参阅:https : //pusher.com/docs/authenticating_users [exp] …

javascript laravel pusher reactjs react-native

5
推荐指数
1
解决办法
717
查看次数

如何在Mac上将PIL安装到Python 3.5?

我是Python安装的新手,并尝试安装PIL.我感觉他们被安装到错误的目录.PIP似乎安装得很好.

Pycharm说

Try to run this command from the system terminal. Make sure that you
use the correct version of 'pip' installed for your Python interpreter
located at
'/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5'.
Run Code Online (Sandbox Code Playgroud)

但是在检查终端时回复是

Jamess-MacBook-Pro:~ JamesParsons$ pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in
/Library/Python/2.7/site-packages
Run Code Online (Sandbox Code Playgroud)

它还提到了不同版本的Python.

安装PIL的最佳方法是什么,因为Pycharm仍然会提出未解决的参考?

python macos python-imaging-library

2
推荐指数
1
解决办法
6203
查看次数

如何在控制器构造函数中添加两个中间件

在Controller构造函数中添加这两个中间件的正确方法是什么?

Route::get('admin', ['middleware' => ['auth', 'admin'], function()

我有以下显然是不正确的.

public function __construct()
{
    $this->middleware('auth','admin');
}
Run Code Online (Sandbox Code Playgroud)

php laravel-5 laravel-5.2

2
推荐指数
1
解决办法
2382
查看次数

我已经用brew更新了yarn,但我无法再运行yarn命令

我已经用brew更新了yarn,但我无法再运行yarn命令。我尝试从brew和npm卸载并重新安装并清除所有缓存,但没有成功。当前安装的版本是1.22.4。

internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module '/Users/..../.yarn/releases/yarn-1.22.0.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Run Code Online (Sandbox Code Playgroud)

node.js npm node-modules yarnpkg

2
推荐指数
1
解决办法
874
查看次数

Vue.js来自对象键和嵌套数组的v-for循环

我在另一个v-for中安静了一个复杂的v-for循环.基本上显示问题列表和该问题的答案列表.我计划获取问题的密钥,并将其用于groups_answers的密钥.

v-for循环如下:

        <div v-for="question in questions.questions">
          {{question.question}}
          <div v-for="a in grouped_answers[0].answers">
            {{a.answer}}
          </div>
        </div>
Run Code Online (Sandbox Code Playgroud)

目前返回错误:

无法读取undefined的属性'答案'.

grouped_answers对象示例如下:

[
  {
    "question_id": 1,
    "answers": [
      {
        "id": 1,
        "answer": "Cat"
      },
      {
        "id": 2,
        "answer": "Dog"
      }
    ]
  },
  {
    "question_id": 2,
    "answers": [
      {
        "id": 3,
        "answer": "Fish"
      },
      {
        "id": 4,
        "answer": "Ant"
      }
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

对于完整模板,我附上了以下代码:

<template>
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
              <div v-for="app in appliances">
                <input type="radio" id="one" v-model="appliance"  v-bind:value="app.id" v-on:change="getQuestions">
                <label for="one">{{app.appliance}}</label>
              </div>
              <br> …
Run Code Online (Sandbox Code Playgroud)

javascript loops vue.js vuejs2 v-for

1
推荐指数
1
解决办法
2万
查看次数