Load Stage with JSON String

获取Konva最新的信息

To deserialize a JSON string with Konva, we can use the Konva.Node.create()
method which creates a node from a JSON string. If we want to deserialize
a stage node, we can also pass in an optional container parameter.

That methods works for very small apps. For more complex cases take a look into Complex Load or even better to Best Practices

Konva Simple Load Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Simple Load Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var json =
'{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":100,"y":100,"sides":6,"radius":70,"fill":"red","stroke":"black","strokeWidth":4},"className":"RegularPolygon"}]}]}';

// create node using json string
var stage = Konva.Node.create(json, 'container');
</script>
</body>
</html>