当前位置:网站首页>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
边栏推荐
- Video multiple effects production, fade in effect and border background are added at the same time
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- Fabric.js IText 手动设置斜体
- Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
- Mysql重点难题(2)汇总
- Cubemx DMA notes
- Collectors.groupingBy 排序
- Go Chan's underlying principles
- 4. Flask cooperates with a tag to link internal routes
- Pyflink writes MySQL examples with JDBC
猜你喜欢

Fabric.js 激活输入框

About PROFIBUS: communication backbone network of production plant

操作符详解

Save the CDA from the disc to the computer

Gee: remote sensing image composite and mosaic

Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I

LeetCode 1175. 质数排列(质数判断+组合数学)

7. Eleven state sets of TCP

Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line

Ansible installation and use
随机推荐
延时队列两种实现方式
go实现leetcode旋转数组
函数栈帧的创建和销毁
LS1046nfs挂载文件系统
Gee: use of common mask functions in remote sensing image processing [updatemask]
Splice characters in {{}}
Map in JS (including leetcode examples)
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
JS interview collection test question 1
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
Mathematical knowledge -- understanding and examples of fast power
Video multiple effects production, fade in effect and border background are added at the same time
[opencv] image binarization
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
Super detailed pycharm tutorial
Using QA band and bit mask in Google Earth engine
Fabric.js 居中元素
Simple and practical accounting software, so that accounts can be checked
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
Collectors.groupingBy 排序