繁体   English   中英

在 Vue 应用程序上显示 RSS Feed 或 API

[英]Display RSS Feed or API on Vue application

我已经尝试了几个月。

我希望在我的 vue.js 应用程序上显示以下 RSS 提要: https : //www.google.ie/alerts/feeds/10663948362751557705/45110340722220974544

但是如何将以下所有内容链接在一起并显示该系列文章? 我在这里挣扎,任何帮助将不胜感激!

我已经设置了一个后端来避免 Express.js 中的 CORS 策略:

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');

const app = express();

app.use(morgan('tiny'));
app.use(cors());
app.use(bodyParser.json());

app.get('/', (req, res) => {
    res.json({
        message: 'Test'
    });
});

const port = process.env.PORT || 4000;
app.listen(port, () => {
    console.log(`listening on ${port}`);
});

谷歌警报组件:

<template>
  </template>

<script>
  export default {

  };
</script>

PostArticles.js:

import axios from 'axios';

const url = 'http://localhost:4000';

export default {
mounted() {
  axios.get('https://www.google.ie/alerts/feeds/10663948362751557705/16000017647453347583')
  .then(function (response) {
    // handle success
  console.log(response);
  })
 .catch(function (error) {
    // handle error
   console.log(error);
 });
}

您的后端使用 CORS 允许任何来源从中读取数据。

您的前端直接从 Google请求 RSS 数据。 它不会靠近您的后端。

Google不会使用 CORS 授予您的前端读取其数据的权限。

您需要更改您的前端,以便它向您的后端询问数据,并且您需要更改您的后端,以便它向前端提供该数据(这意味着让后端从 Google 获取它(并可能保留它的本地缓存) ))。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM