当前位置:网站首页>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
边栏推荐
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- Storage of data
- Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
- Collectors.groupingBy 排序
- 7.1模拟赛总结
- Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
- Using QA band and bit mask in Google Earth engine
- fastText文本分类
- Dark horse notes -- Set Series Collection
- 【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
猜你喜欢
No logic is executed after the El form is validated successfully
Summary of database problems
The underlying principle of go map (storage and capacity expansion)
Pyechart1.19 national air quality exhibition
Nodejs (02) - built in module
Black Horse Notes - - set Series Collection
The El cascader echo only selects the questions that are not displayed
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
Record my pytorch installation process and errors
黑马笔记---Map集合体系
随机推荐
从数组中找出和为目标的下标
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
LeetCode 1175. 质数排列(质数判断+组合数学)
案例分享|智慧化的西部机场
Save the CDA from the disc to the computer
Pyechart1.19 national air quality exhibition
Gee: use of common mask functions in remote sensing image processing [updatemask]
Foreign trade marketing website system development function case making
Fabric.js IText设置指定文字的颜色和背景色
画波形图_数字IC
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js 渐变
[bus interface] Axi interface
leetcode存在重复元素go实现
创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程
Go GC garbage collection notes (three color mark)
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
Exercise notes 13 (effective letter ectopic words)
运维工作的“本手、妙手、俗手”
Implementation of leetcode two number addition go