当前位置:网站首页>Fabric. JS compact JSON
Fabric. JS compact JSON
2022-07-02 05:18:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
If you don't know much about Fabric.js
Serialization and deserialization of , You can see Fabric.js serialize and Fabric.js Deserialization .
<br>
This article will talk about “ Streamlining JSON” It's actually Compact serialization
. Serialization can put Fabric.js
The canvas of is exported as a JSON
object .
When we want to save the canvas to the server , What is transmitted to the background is actually a segment JSON
. If you want to re render , Just put this paragraph JSON
Throw it to Fabric.js
, Call the corresponding method to render to the page .
But if you think Fabric.js
Default exported JSON
Too big 、 If you don't need so many attributes , You can use a thin version of the configuration .
<br>
<br>
Hands on coding
Compare the default export with the compact Export .
I added... To the page 1 A background picture and 2 Basic graphic elements , If you use the default serialization , The object is really a little more .
If you only need core attributes , Just for rendering , That can be used “ Thin serialization ”.
<canvas id="canvasBox" width="600" height="600" style="border: 1px solid #ccc;"></canvas><!-- introduce Fabric.js --><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/521/fabric.js"></script><script> // Initialize canvas canvas = new fabric.Canvas('canvasBox', { includeDefaultValues: false // instructions toObject/toDatalessObject Whether the default value should be included , If set to false, Takes precedence over the object value }) console.log(canvas.toObject()) // Output serialized content </script>
《canvas.includeDefaultValues file 》
take includeDefaultValues
Set to false
You can make canvas.toObject()
Method outputs a reduced JSON
.
includeDefaultValues
The default value of is true
, So the basic version will be output by default JSON
Content .
<br>
You can modify it includeDefaultValues
Value , Observe the changes of the output object .
<br>
I need to remind you : If your project needs only to see results , You don't need to worry about too many internal attributes , You can try to use the content mentioned in this article , The reduced data is transmitted to the back end , This saves space .
<br>
Careful students should also see , Even after the reduction JSON
data , The version number will still be saved in it . If the version number doesn't work for you , You can also use it JS
The method of version
Get rid of . But I don't suggest you do this .
<br>
<br>
Source warehouse
<br>
<br>
Recommended reading
《Fabric.js How to use the brush ?》
《Fabric.js How to use an eraser ( Including recovery function )》
《Fabric.js From entry to defiance 》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
- Find the subscript with and as the target from the array
- 运维工作的“本手、妙手、俗手”
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- Map in JS (including leetcode examples)
- Nodejs (02) - built in module
- Nodejs (03) -- custom module
- Go Chan's underlying principles
- Fabric.js 自由绘制矩形
- Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
猜你喜欢
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
How to configure PostgreSQL 12.9 to allow remote connections
7.TCP的十一种状态集
Fabric.js 激活输入框
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
Go Chan's underlying principles
黑马笔记---Set系列集合
Creation and destruction of function stack frames
Record my pytorch installation process and errors
数据库问题汇总
随机推荐
Gee series: Unit 4 data import and export in Google Earth engine
leetcode两数相加go实现
黑马笔记---Set系列集合
Find the subscript with and as the target from the array
Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
函数栈帧的创建和销毁
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
Mathematical knowledge -- understanding and examples of fast power
Operator details
Super detailed pycharm tutorial
Mapping settings in elk (8) es
Dark horse notes -- map set system
7. Eleven state sets of TCP
go实现leetcode旋转数组
Ansible installation and use
How to configure PostgreSQL 12.9 to allow remote connections
Video cover image setting, put cover images into multiple videos in the simplest way
Draw a wave chart_ Digital IC