欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue配置marked鏈接添加target="_blank"的方法

 更新時(shí)間:2019年07月19日 11:26:47   作者:試毅_思偉  
這篇文章主要介紹了Vue配置marked鏈接添加target="_blank"的方法,文中給大家提到了vue實(shí)現(xiàn)類似target="_blank"打開新窗口的代碼,感興趣的朋友參考下吧

1."引入marked

package.json

"dependencies": {
  "marked": "^0.3.9"
}
import marked from "marked";

1.修改生成的HTML的方法

const renderer = new marked.Renderer();
//https://github.com/markedjs/marked/issues/655#issuecomment-383226346
const linkRenderer = renderer.link;
renderer.link = (href, title, text) => {
  const html = linkRenderer.call(renderer, href, title, text);
  return html.replace(/^<a /, '<a target="_blank" ');
};
const html = marked(markdown, { renderer });

Tips:marked參數(shù)配置

const renderer = new marked.Renderer();
//基本設(shè)置
marked.setOptions({
  renderer: renderer,
  gfm: true, //允許 Git Hub標(biāo)準(zhǔn)的markdown.
  tables: true, //允許支持表格語法(該選項(xiàng)要求 gfm 為true)
  breaks: true, //允許回車換行(該選項(xiàng)要求 gfm 為true)
  pedantic: false, //不糾正原始模型任何的不良行為和錯(cuò)誤(默認(rèn)為false)
  sanitize: false, //對輸出進(jìn)行過濾(清理),將忽略任何已經(jīng)輸入的html代碼(標(biāo)簽)
  smartLists: true, //使用比原生markdown更時(shí)髦的列表
  smartypants: false //使用更為時(shí)髦的標(biāo)點(diǎn)
});

ps:vue實(shí)現(xiàn)類似target="_blank"打開新窗口

//href的{}不能少
let {href} = this.$router.resolve({path:'/applySocSecCard'});
window.open(href, '_blank');

總結(jié)

以上所述是小編給大家介紹的Vue配置marked鏈接添加target="_blank"的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評(píng)論