去掉例如以下属性:
解决办法:
- (1)安装
npm install cheerio
- (2)引入
nuxt.config.js
import cheerio from 'cheerio'
export default {
hooks: {
'render:route': (url, result) => {
this.$ = cheerio.load(result.html,{decodeEntities: false});
this.$(`meta`).removeAttr('data-n-head');
result.html = this.$.html()
}
}
}
- (3)OK了
操作其他属性一样的操作,cheerio的选择器以及语法和jQuery十分相似。
cheerio是jquery核心功能的一个快速灵活而又简洁的实现,主要是为了用在服务器端需要对DOM进行操作的地方
让你在服务器端和html愉快的玩耍