前端vue2如何处理Rss订阅、聚合,前端 vue2 如何处理xml 格式的数据

文章目录

    • 前言
    • 解决

前言

最近看见csdn有Rss订阅这个功能,但发现这个接口响应的数据格式不是常用的Json格式而是xml,即下图的格式。

在这里插入图片描述

附响应的代码

<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[amoureux555的博客]]></title><description><![CDATA[前端、js、npm、node、css、html]]></description><link>https://blog.csdn.net/qq_46123200</link><language>zh-cn</language><generator>https://blog.csdn.net/</generator><copyright><![CDATA[Copyright &copy; qq_46123200]]></copyright><item><title><![CDATA[【已解决】Vue 3+TS项目,无法找到模块“XXX”的声明文件,项目报错无法找到声明文件]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136903232</link><guid>https://blog.csdn.net/qq_46123200/article/details/136903232</guid><author>qq_46123200</author><pubDate>Thu, 21 Mar 2024 11:28:26 +0800</pubDate><description><![CDATA[【已解决】Vue 3+TS项目,无法找到模块“XXX”的声明文件,项目报错无法找到声明文件]]></description><category></category></item><item><title><![CDATA[无法找到模块“pinia-plugin-persist”的声明文件。“c:/Users/16566/Desktop/demo/,pinia持久化依赖报错,解决亲测有效]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136882974</link><guid>https://blog.csdn.net/qq_46123200/article/details/136882974</guid><author>qq_46123200</author><pubDate>Wed, 20 Mar 2024 17:27:05 +0800</pubDate><description><![CDATA[无法找到模块“pinia-plugin-persist”的声明文件。“c:/Users/16566/Desktop/demo/,pinia持久化依赖报错,解决亲测有效]]></description><category></category></item><item><title><![CDATA[关于vue轮播vue-seamless-scroll自动滚动插件复制出来的数据点击事件无效]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136850733</link><guid>https://blog.csdn.net/qq_46123200/article/details/136850733</guid><author>qq_46123200</author><pubDate>Wed, 20 Mar 2024 08:00:00 +0800</pubDate><description><![CDATA[vue-seamless-scroll 滚动插件的使用及循环的列表点击事件不生效的解决方案,vue-seamless-scroll 点击click失效]]></description><category></category></item><item><title><![CDATA[vue2中使用vue-seamless-scroll时出现数据重复或者样式错乱问题]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136841560</link><guid>https://blog.csdn.net/qq_46123200/article/details/136841560</guid><author>qq_46123200</author><pubDate>Tue, 19 Mar 2024 14:19:21 +0800</pubDate><description><![CDATA[vue2中使用vue-seamless-scroll时出现数据重复或者样式错乱问题,前端使用vue-seamless-scroll出现数据重复或者样式错乱问题,部分没样式,上下样式不一样]]></description><category></category></item><item><title><![CDATA[vue2 实现数字滚动效果,翻页效果]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136821291</link><guid>https://blog.csdn.net/qq_46123200/article/details/136821291</guid><author>qq_46123200</author><pubDate>Tue, 19 Mar 2024 08:00:00 +0800</pubDate><description><![CDATA[vue2 实现数字,数值自动滚动效果,翻页效果,引入直接使用]]></description><category></category></item><item><title><![CDATA[vscode中Chinese (Simplified)汉化无效解决方法]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136738457</link><guid>https://blog.csdn.net/qq_46123200/article/details/136738457</guid><author>qq_46123200</author><pubDate>Fri, 15 Mar 2024 14:23:15 +0800</pubDate><description><![CDATA[vscode中Chinese (Simplified)汉化无效解决方法]]></description><category></category></item><item><title><![CDATA[vue项目如何禁止屏幕缩放,vue项目进行浏览器进行缩放]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136507090</link><guid>https://blog.csdn.net/qq_46123200/article/details/136507090</guid><author>qq_46123200</author><pubDate>Wed, 06 Mar 2024 15:13:45 +0800</pubDate><description><![CDATA[vue项目如何禁止屏幕缩放,vue项目进行浏览器进行缩放]]></description><category></category></item><item><title><![CDATA[windows系统下,如何给文件夹添加备注?文件夹查看备注]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136484529</link><guid>https://blog.csdn.net/qq_46123200/article/details/136484529</guid><author>qq_46123200</author><pubDate>Wed, 06 Mar 2024 10:07:43 +0800</pubDate><description><![CDATA[windows系统下,如何给文件夹添加备注?文件夹查看备注]]></description><category></category></item><item><title><![CDATA[Failed to load module script: Expected a JavaScript module script but the server responded with a MI]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136483060</link><guid>https://blog.csdn.net/qq_46123200/article/details/136483060</guid><author>qq_46123200</author><pubDate>Tue, 05 Mar 2024 16:43:12 +0800</pubDate><description><![CDATA[项目打包报错`Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.`
]]></description><category></category></item><item><title><![CDATA[vscode 使用ssh进行远程开发 (remote-ssh),首次连接及后续使用,详细介绍]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136193576</link><guid>https://blog.csdn.net/qq_46123200/article/details/136193576</guid><author>qq_46123200</author><pubDate>Mon, 04 Mar 2024 16:47:20 +0800</pubDate><description><![CDATA[vscode 使用ssh进行远程开发 (remote-ssh),首次连接及后续使用,详细介绍]]></description><category></category></item><item><title><![CDATA[前端 Vue启动本地(.exe)文件]]></title><link>https://blog.csdn.net/qq_46123200/article/details/136191265</link><guid>https://blog.csdn.net/qq_46123200/article/details/136191265</guid><author>qq_46123200</author><pubDate>Tue, 20 Feb 2024 15:41:10 +0800</pubDate><description><![CDATA[前端 Vue启动本地(.exe)文件]]></description><category></category></item><item><title><![CDATA[ubuntu 20.04系统,桌面有个文件夹名为0.7.0,每次系统启动后都需要打开终端,进入0.7.0文件夹,然后执行命令./webrtc-streamer命令,如何设置开机自动打开终端执行]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135869527</link><guid>https://blog.csdn.net/qq_46123200/article/details/135869527</guid><author>qq_46123200</author><pubDate>Fri, 26 Jan 2024 16:29:24 +0800</pubDate><description><![CDATA[ubuntu 20.04系统,桌面有个文件夹名为0.7.0,每次系统启动后都需要打开终端,进入0.7.0文件夹,然后执行命令./webrtc-streamer命令,如何设置开机自动打开终端执行]]></description><category></category></item><item><title><![CDATA[VMware 17 中 安装 Ubuntu 系统,系统中安装todesk与向日葵。其他设备无法通过todesk和向日葵远控问题]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135840220</link><guid>https://blog.csdn.net/qq_46123200/article/details/135840220</guid><author>qq_46123200</author><pubDate>Thu, 25 Jan 2024 11:30:02 +0800</pubDate><description><![CDATA[todesk连接ubuntu显示当前系统并无桌面环境,或无显示器,无法显示远程桌面,您需要自行安装X11桌面环境,或者使用终端文件功能]]></description><category></category></item><item><title><![CDATA[ubuntu 20.04 使用 webrtc-streamer自动退出,报错GLIBC 问题解决方法]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135780846</link><guid>https://blog.csdn.net/qq_46123200/article/details/135780846</guid><author>qq_46123200</author><pubDate>Tue, 23 Jan 2024 19:21:40 +0800</pubDate><description><![CDATA[Ubuntu 20.04 部署webrtc-streamer视频流遇到的问题,及解决方法。webrtc-streamer报错、启动不起来。rtsp视频流播放失败问题。亲测有效]]></description><category></category></item><item><title><![CDATA[Ubuntu 常用命令、docker 常用命令、unzip常用命令、tar常用命令]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135755440</link><guid>https://blog.csdn.net/qq_46123200/article/details/135755440</guid><author>qq_46123200</author><pubDate>Tue, 23 Jan 2024 09:04:56 +0800</pubDate><description><![CDATA[ubuntu 复制文件夹下文件到其他文件夹下。查看容器的命令(无论运行还是停止)查看正在运行容器的命令。]]></description><category></category></item><item><title><![CDATA[windows 11安装VMware 17 ,VMware安装Ubuntu 20.4,ssh传文件]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135749655</link><guid>https://blog.csdn.net/qq_46123200/article/details/135749655</guid><author>qq_46123200</author><pubDate>Mon, 22 Jan 2024 16:18:35 +0800</pubDate><description><![CDATA[小白都能学会的,在windows 11安装VMware 17 ,VMware安装Ubuntu 20.4,ssh传文件手把手教你]]></description><category></category></item><item><title><![CDATA[【ubuntu】ubuntu 20.04安装docker,使用nginx部署前端项目,nginx.conf文件配置]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135615589</link><guid>https://blog.csdn.net/qq_46123200/article/details/135615589</guid><author>qq_46123200</author><pubDate>Tue, 16 Jan 2024 10:24:39 +0800</pubDate><description><![CDATA[ubuntu 20.04安装docker,使用nginx部署前端项目]]></description><category></category></item><item><title><![CDATA[【ubuntu】docker中如何ping其他ip或外网]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135608274</link><guid>https://blog.csdn.net/qq_46123200/article/details/135608274</guid><author>qq_46123200</author><pubDate>Mon, 15 Jan 2024 18:39:41 +0800</pubDate><description><![CDATA[docker中如何ping其他ip或外网]]></description><category></category></item><item><title><![CDATA[级联选择器el-cascader根据下拉数据的id获取所对应的文字]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135193901</link><guid>https://blog.csdn.net/qq_46123200/article/details/135193901</guid><author>qq_46123200</author><pubDate>Mon, 25 Dec 2023 10:39:23 +0800</pubDate><description><![CDATA[级联选择器el-cascader根据下拉数据的id获取所对应的文字]]></description><category></category></item><item><title><![CDATA[【DataV】DataV组件库——更新数据视图不更新]]></title><link>https://blog.csdn.net/qq_46123200/article/details/135192425</link><guid>https://blog.csdn.net/qq_46123200/article/details/135192425</guid><author>qq_46123200</author><pubDate>Mon, 25 Dec 2023 10:00:01 +0800</pubDate><description><![CDATA[大屏DataV组件库——更新数据视图不更新]]></description><category></category></item></channel></rss>

解决

那么在项目中怎么处理这种数据格式,变成我们好处理的数据呢,通过rss-parser,以vue2 项目为例

下载依赖

npm i rss-parser

处理代码:

<template><div class="other-item"><div class="inner"><ul class="hot-list-article"><li v-for="(item, i) in data.items" :key="i" @click="JumpFn(item)">{{ item.title }}</li></ul></div></div>
</template>
<script>
// 导入依赖
import RSSParser from 'rss-parser';export default {data() {return {data: {},};},created() {this.searchBtn()},methods: {// 点击跳转事件JumpFn(item) {console.log("🚀 ~ JumpFn ~ item:", item)// 打开一个新的页面window.open(item.link, '_blank');},// RSS 事件searchBtn() {this.searchList = [];const xhr = new XMLHttpRequest();xhr.onreadystatechange = () => {// 引入并new一个新的parserconst parser = new RSSParser();// 判断是否返回if (xhr.readyState === 4) {// 判断返回的状态if (xhr.status === 200) {const data = xhr.responseTextparser.parseString(data).then((res) => {this.data = res})} else {console.log("请求接口失败")}}};xhr.open("get", process.env.VUE_APP_BASE_API);// VUE_APP_BASE_API 是请求接口的地址,我这里请求的地址是https://rss.csdn.net/qq_46123200/rss/map?spm=1001.2014.3001.5494xhr.send(null);},},
} 
</script>
<style lang="scss" scoped>
ul {li {text-align: left;font-size: 16px;cursor: pointer;&:hover {color: #2ea7e0;}}
}.other-item-title {margin: 10px 20px;padding: 5px;line-height: 30px;font-weight: 400;border-bottom: 1px solid #e8e9e7;color: #383937;position: relative;font-size: 18px
}.other-item .inner {margin: 0 20px;padding-bottom: 10px
}.inner .hot-list-article li {display: block;line-height: 32px;position: relative;margin: 3px 0;counter-increment: nums;padding-left: 30px;overflow: hidden;word-wrap: normal !important;white-space: nowrap;text-overflow: ellipsis
}.hot-list-article li a {color: #787977
}.hot-list-article li:before {color: #000;width: 22px;height: 22px;line-height: 22px;text-align: center;content: counter(nums, decimal);position: absolute;left: 0;top: 5px;border-radius: 100%;background-color: #edefee;text-shadow: 0 1px 0 rgba(255, 255, 255, .5);font-family: SourceCodeProRegular, Menlo, Monaco, Consolas, "Courier New", monospace, 'Helvetica Neue', Arial, sans-serif
}/*以上就是一个稍微好看的有编号的li列表 */
/*加上以下之后,排名前三的数据编号就添加了编号颜色,更好看*/
.hot-list-article li:first-child:before,
.hot-list-article li:nth-child(2):before,
.hot-list-article li:nth-child(3):before {color: #fff;text-shadow: none
}.hot-list-article li:first-child:before {background-color: #e24d46
}/*第1行的行号样式*/
.hot-list-article li:nth-child(2):before {background-color: #2ea7e0
}/*第2行的行号样式*/
.hot-list-article li:nth-child(3):before {background-color: #6bc30d
}/*第3行的行号样式*/
.hot-list-article li a:hover {text-decoration: underline;color: #6bc30d
}/*鼠标移过更好看*/
</style>

上面附上了处理的源码,如果接口请求不通,可以直接复制最上面的响应体进行测试。

下班~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/557562.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ubuntu將en01變成eth0的形式

文章目录 前言一、操作步驟1、打開grub文件2、輸入更新指令3、查看結果 二、使用步骤总结 前言 一、操作步驟 1、打開grub文件 使用管理員權限打開&#xff0c;添加新內容 sudo gedit grub2、輸入更新指令 sudo update-grub3、查看結果 使用ifconfig查看是否修改成功&…

STM32利用串口外设发送数据

今天2024.3.21日上午学习了一下基本的串口初始化&#xff0c;利用串口发送一个字节的数据&#xff0c;看时间也快11点了&#xff0c;上午就学习这么多吧&#xff0c;把上午的知识总结一下&#xff0c;串口初始化的过程&#xff1a; 看着图来编写串口初始化的过程&#xff1a; …

docker 修改日志存储路径

docker 日志默认存放在 /var/lib/docker/ 下 docker info修改步骤&#xff1a; 1、停止docker服务 systemctl stop docker 2、新建配置文件 vi /etc/docker/daemon.json添加如下内容 {"data-root": "/data/docker" }3、然后把之前的数据全部复制到新目…

【Linux多线程】线程的概念

【Linux多线程】线程的概念 目录 【Linux多线程】线程的概念Linux线程的概念什么是线程重新定义线程和进程 进程地址空间第四讲线程的优点线程的缺点线程异常线程的用途 Linux进程VS线程进程和线程关于进程线程的问题 Linux线程控制POSIX线程库创建线程如何给线程传参&#xff…

算法沉淀——贪心算法七(leetcode真题剖析)

算法沉淀——贪心算法七 01.整数替换02.俄罗斯套娃信封问题03.可被三整除的最大和04.距离相等的条形码05.重构字符串 01.整数替换 题目链接&#xff1a;https://leetcode.cn/problems/integer-replacement/ 给定一个正整数 n &#xff0c;你可以做如下操作&#xff1a; 如果…

【数据库系统】SQL和T-SQL

第四章 SQL 基本内容 系统结构、DDL、DML、视图、数据控制、嵌入式SQL SQL介绍 特点 一体化&#xff1b;面向集合操作&#xff1b;非过程化语言&#xff1b;可以单独写&#xff0c;也可以作为嵌入式语言&#xff08;JDBC&#xff09; 体系结构 数据库存储结构 逻辑存储结构 面…

华曦传媒陆锋:数字媒体时代,社区电梯广告价值正在被重估

在数字化时代的浪潮中&#xff0c;电梯广告、停车场道闸广告、门禁灯箱广告等线下社区广告似乎面临着生存的挑战。 然而&#xff0c;这一传统广告形式展现出了惊人的韧性和价值。 比如&#xff0c;2023年上半年&#xff0c;作为行业龙头分众传媒&#xff0c;2023年上半年实现…

k8s系列之十五 Istio 部署Bookinfo 应用

Bookinfo 应用中的几个微服务是由不同的语言编写的。 这些服务对 Istio 并无依赖&#xff0c;但是构成了一个有代表性的服务网格的例子&#xff1a;它由多个服务、多个语言构成&#xff0c;并且 reviews 服务具有多个版本。 该应用由四个单独的微服务构成。 这个应用模仿在线书…

前端案例:产品模块

文章目录 产品模块效果结构布局分析父级盒子布局图片和段落评价和详情 产品模块效果 结构布局分析 1、大的父级盒子包含全部的内容 2、内容装入 图片&#xff08;img标签&#xff09;&#xff1b;分别三个子盒子装入两段评价以及商品信息。 父级盒子布局 div {width: 300px…

python智慧农业小程序flask-django-php-nodejs

当今社会已经步入了科学技术进步和经济社会快速发展的新时期&#xff0c;国际信息和学术交流也不断加强&#xff0c;计算机技术对经济社会发展和人民生活改善的影响也日益突出&#xff0c;人类的生存和思考方式也产生了变化。传统智慧农业采取了人工的管理方法&#xff0c;但这…

HTTPS 协议原理

目录 HTTPS VS HTTP HTTPS是什么 概念准备 常见的加密方式 对称加密 一个简单的对称加密例子 非对称加密 数据摘要&&数据指纹 数字签名 HTTPS 的工作过程探究 方案1-只使用对称加密 方案2-只使用非对称加密 方案3-双方都使用非对称加密 方案4-非对称加密…

线段树+暴力区修 P4145 上帝造题的七分钟 2 / 花神游历各国

传送门https://www.luogu.com.cn/problem/P4145 这道题着实想了好久&#xff0c;本来想的是用数学方法找规律&#xff0c;结果写了好久&#xff0c;发现想假了&#xff0c;于是只好看思路&#xff0c;暴力区修&#xff01;原因是被开根号一定次数就会变成1&#xff0c;是有限的…