现在ES6用的越来越多,想要学习使用ES6,只需简单搭建引入几个js即可运行ES6代码
但是需要基本的服务器环境下运行(如http://10.12.8.161:8047/js-test/export/export.html 这样服务器环境访问)。
引入这几个js
<script type="text/javascript" src="./bower_components/jQuery/dist/jquery.min.js"></script> <script type="text/javascript" src="./bower_components/traceur/traceur.js"></script> <script type="text/javascript" src="./bower_components/bootstrap/dist/js/bootstrap.js" ></script>
ES6 js 文件运行需要设置
type="module"
<script type=‘module‘> import * as cc from ‘./js/main.js‘; console.log(cc); </script>
完整示例:
<html> <head> <meta charset="UTF-8"> <title>es6</title> <script type="text/javascript" src="./bower_components/jQuery/dist/jquery.min.js"></script> <script type="text/javascript" src="./bower_components/traceur/traceur.js"></script> <script type="text/javascript" src="./bower_components/bootstrap/dist/js/bootstrap.js" ></script> <script type="text/javascript"> //traceur.options.experimental = true; </script> </head> <body> <script type=‘module‘> import * as cc from ‘./js/main.js‘; console.log(cc); </script> </body> </html>
下载:
https://files.cnblogs.com/files/zhidong123/ES6.zip
原文地址:https://www.cnblogs.com/zhidong123/p/9970903.html
时间: 2024-10-21 19:15:02