admin管理员组

文章数量:1144901

i have made some blocks before with @wordpress/create-block now i wanted to work on a new block, and it seem there is a new file: view.js.

i have searched the web and ducomentation in the handbook, and maybe i am missing something, but couldn't find anything on it.is it there for custom javascript code ? is it only applicable for the front end?

so what is the view.js file for?

best regards

i have made some blocks before with @wordpress/create-block now i wanted to work on a new block, and it seem there is a new file: view.js.

i have searched the web and ducomentation in the handbook, and maybe i am missing something, but couldn't find anything on it.is it there for custom javascript code ? is it only applicable for the front end?

so what is the view.js file for?

best regards

Share Improve this question asked Nov 8, 2023 at 7:42 RonRon 1657 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The filename is not really relevant. You should check block.json to see where the file is actually being used. I would guess that it's being used for the viewScript property, in which case you can check its purpose by looking for the documentation for that property, rather than anything about "view.js" alone.

As noted in the documentation, the viewScript file is a script that will be loaded on the front end when the block is used. This is where any interactivity your block might have would be implemented if it's not relevant in the editor.

本文标签: block editorwhat is the function of the viewjs file