wordpress - 在 Vue 中解析 v-html 内容
问题描述
我有一个页面,我目前正在使用 Wordpress 的 REST api 获取 html 字符串。我希望能够创建一个导航栏组件来解析 html,查看所有标题标签并为每个标题生成锚链接。是否可以使用Vue搜索v-html来动态创建这个组件?
这是获取 wordpress 数据的 axios 调用。我得到的终点是从一个帖子页面返回“内容”——这是一个我正在使用 v-html 呈现的 HTML 字符串。
data() {
return {
loading: true,
baseUrl: 'https://sitename.co.uk/wp-json/wp/v2/posts/'
}
},
methods: {
fetchData() {
axios.get(`${this.baseUrl}${this.$route.params.id}/`)
.then((resp) => {
const data = resp.data; //this is the wp data
})
.catch((err) => {
console.log(err);
})
}
}
解决方案
据我所知,您无法在 v-html 中导入 head 标签,因此,您可以在 vue js 中使用 _slug 将组件呈现为静态页面。
推荐阅读
- r - ggplot2 堆积条形图 - 每个条为 100%,每个条内都有百分比标签
- javascript - 单元测试未定义不是对象(评估“this.groups.map”)
- javascript - 基于先前调用的响应的异步调用,避免回调地狱
- c# - 正则表达式验证 Windows UNC 路径
- java - 运行 mvn 原型时出错:生成
- c# - 使用动态注入类创建委托
- python - 将 Python str 转换为 C const char *
- c# - 如何为 C# 生成序列化器/反序列化器代码?
- java - Camel CxfEndpoint 拦截器失败
- thymeleaf - 带有迭代器的 Thymeleaf 条件