vue.jsでCORSエラーを回避したいですが、方法がよくわかりませんでした。
jsonpを利用してもエラーは回避できませんでした。
const jsonp = require( 'node-jsonp' ); export const get_ip_address_jsonp = () => { return new Promise( ( resolve, reject ) => { jsonp( 'http://gd.geobytes.com/GetCityDetails', function( data ) { console.log( '#####################jsonp data', data ); //resolve( data.geobytesipaddress ); } ); } ); };
<script lang="ts"> import { get_ip_address_jsonp } from '@/repository/jsonp'; @Component export default class extends Vue { async created() { const ipaddress = await get_ip_address_jsonp(); } }
エラー
Access to fetch at 'http://gd.geobytes.com/GetCityDetails?callback=jsonp1560399993697' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. economic:1 Uncaught (in promise) TypeError: Failed to fetch
改善方法がありましたらご教示いただけますでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。