【转】微信小程序原生代码快速转换mpuve(vue)代码(仅供娱乐)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
  <textarea id="code"></textarea>
  <div id="result"></div>
  <script>
    $(function() {
      $(‘#code‘).on(‘input‘,(e) => {
        let val = e.currentTarget.value
        // for
        val = val.replace(/wx:for=["|‘]\s*\{\{([^\}]+)\}\}\s*["|‘]/g, ($0,$1) => ‘v-for="(item, index) in ‘ + $1 + ‘"‘)
        val = val.replace(/wx:key=["|‘]([^"|‘]+)["|‘]/g, ($0,$1) => ‘:key="‘ + $1 + ‘"‘)
        // if
        val = val.replace(/wx:if=["|‘]\s*\{\{([^\}]+)\}\}\s*["|‘]/g, ($0, $1) => ‘v-if="‘ + $1 + ‘"‘)
        // 变量
        // val = val.replace(/data-([^=|\s]+)=["|‘]\{\{([^\}]+)\}\}["|‘]/g, ($0,$1,$2)=> ‘:data-‘+$1+‘="‘+$2+‘"‘)
        val = val.replace(/([^\s|=]+)=["|‘]\{\{([^\}]+)\}\}["|‘]/g, ($0,$1,$2)=> ‘:‘+$1+‘="‘+$2+‘"‘)
        val = val.replace(/<view/g, ‘<div‘)
        val = val.replace(/\/view>/g, ‘\/div>‘)
        val = val.replace(/<text/g, ‘<span‘)
        val = val.replace(/\/text>/g, ‘\/text>‘)
        val = val.replace(/<image([^>]+)/g, ($0,$1) => ‘<img ‘+$1 + ‘/>‘)
        val = val.replace(/<icon([^>]+)/g, ($0,$1) => ‘<i style="display:inline-block" ‘+$1 + ‘/>‘)
        val = val.replace(/bind([^=|\s]+)=["|‘]([^"|‘|\s]+)["|‘]/g, ($0,$1,$2)=>‘@‘+$1+‘="‘+$2+‘"‘)
        $(‘#result‘).text(val)
      })
    })
    
  </script>
</body>
</html>

  转:https://blog.csdn.net/jeason_L/article/details/95051191

【转】微信小程序原生代码快速转换mpuve(vue)代码(仅供娱乐)

上一篇:asp.net(c#)网页跳转七种方法小结


下一篇:在OpenERP8.0中如何激活及时通讯功能im