【发布时间】:2019-07-24 11:39:39
【问题描述】:
我有一个用于 Nuxt.js 的实用程序插件,我使用一种方法来解析主题标签和提及并将它们替换为 <nuxt-link>。然后我使用v-html 将转换后的数据注入回模板中。我的问题是 <nuxt-link> 没有被 v-html 解析。
import Vue from 'vue';
Vue.mixin({
methods: {
replaceMentions(data) {
// Tags
const tagRegEx = /\[#tag:[a-zA-Z0-9_-]*\]/g;
let tagMatch;
while ((tagMatch = tagRegEx.exec(data)) !== null) {
const tag = Array.from(tagMatch[0].matchAll(/\[#tag:(.*?)\]/g));
data = data.replace(tag[0][0], '<nuxt-link to="/search?q=' + tag[0][1] + '">#' + tag[0][1] + '</a>');
};
// Users
const userRegEx = /\[@user:[a-zA-Z0-9_-]*\]/g;
let userMatch;
while ((userMatch = userRegEx.exec(data)) !== null) {
const user = Array.from(userMatch[0].matchAll(/\[@user:(.*?)\]/g));
data = data.replace(user[0][0], '<nuxt-link to="/users/' + user[0][1] + '">@' + user[0][1] + '</>');
};
return data;
}
}
});
有没有人有关于如何使这些作为正确的 nuxt 兼容链接工作的提示?我已经尝试过使用<a> 并且效果很好,我只想使用适当的 nuxt 兼容链接。
【问题讨论】: