Vue中如何封装通用方法集锦?

2026-05-22 10:301阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计3578个文字,预计阅读时间需要15分钟。

Vue中如何封装通用方法集锦?

javascript// +公共方法+ let _utils={ // +对一段指定的字符串应用HTML编码。+// +@param +// +@returns {String}+encodeHtml: function() { if (typeof==='string') { return .replace(//g, '>'); }}

Vue中如何封装通用方法集锦?

// 公共方法 let _utils = { /** * 对一段指定的字符串应用 HTML 编码。 * @paramhtml * @returns{*} */ encodeHtml: html => { if (typeof (html) == 'string') { return html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#039;').replace(/"/g, '&quot;'); } else { return html; } }, /** * 对一段指定的字符串应用 HTML 解码。
阅读全文

本文共计3578个文字,预计阅读时间需要15分钟。

Vue中如何封装通用方法集锦?

javascript// +公共方法+ let _utils={ // +对一段指定的字符串应用HTML编码。+// +@param +// +@returns {String}+encodeHtml: function() { if (typeof==='string') { return .replace(//g, '>'); }}

Vue中如何封装通用方法集锦?

// 公共方法 let _utils = { /** * 对一段指定的字符串应用 HTML 编码。 * @paramhtml * @returns{*} */ encodeHtml: html => { if (typeof (html) == 'string') { return html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#039;').replace(/"/g, '&quot;'); } else { return html; } }, /** * 对一段指定的字符串应用 HTML 解码。
阅读全文