我是paperJS的新手,我正在尝试在html中包含一个外部paperscript文件,但是它不起作用。内联脚本运行良好时。我的代码是:

HTML代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/paper.js"></script>
</head>
<body>
    <script type="text/paperscript" src = "js/myScript.js" canvas = "myCanvas" >
    </script>
    <canvas id="myCanvas" resize></canvas>



    

paperScript代码(myScript.js):

// Create a Paper.js Path to draw a line into it:
var path = new Path();
// Give the stroke a color
path.strokeColor = 'black';
var start = new Point(100, 100);
// Move to start and draw a line from there
path.moveTo(start);
// Note the plus operator on Point objects.
// PaperScript does that for us, and much more!
path.lineTo(start + [ 100, -50 ]);


我在stackOverflow上发现了一个旧链接,该链接显示使用0.9.10版可解决此问题。但是在新版本中仍然无法解决该问题吗?
这是链接:

How to use paperscript from external source?

最佳答案

这不是paperJs问题。在这里,我试图从本地文件系统加载资源,而chrome不允许这样做(违反其同源策略),因此我们需要一个本地Web服务器。Why?

可以使用WAMP(在Windows上),MAMP(在OS X上)和LAMP(对于ubuntu)来设置本地Web服务器。它也可以由Python http-server和NodeJS http-server设置。

09-12 19:55