web-scope.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package advanced_functions
  2. import (
  3. "github.com/qor5/docs/docsrc/examples/e00_basics"
  4. "github.com/qor5/docs/docsrc/generated"
  5. "github.com/qor5/docs/docsrc/utils"
  6. . "github.com/theplant/docgo"
  7. "github.com/theplant/docgo/ch"
  8. )
  9. var WebScope = Doc(
  10. Markdown(`
  11. ### Use Locals to init vue variables
  12. There is a concept of reactive object in vue. Reactive object can trigger view updates, and [Vue cannot detect normal property additions (e.g. this.myObject.newProperty = 'hi')](https://vuejs.org/v2/api/#Vue-set).
  13. We pre-set the "locals" object as a reactive object, and then we can initialize various types of values and slot it into "locals". And the valid scopes of these values are all inside web.Scope().
  14. For example:
  15. `),
  16. ch.Code(generated.WebScopeUseLocalsSample1).Language("go"),
  17. utils.Demo("Web Scope Use Locals", e00_basics.WebScopeUseLocalsPagePath, "e00_basics/web-scope.go"),
  18. Markdown(`
  19. Use ~web.Scope()~ to determine the effective scope of the variable, then use ~.Init(...).VSlot("{ locals }")~ to initialize the variable and slot it into the ~locals~ object.
  20. In ~VBtn("")~, you can use the ~click~ event to change the variable value in ~locals~ to achieve the effect that the page changes with the click.
  21. In ~VBtn("Test Can Not Change Other Scope")~, values in ~locals~ will not change with the click, because the button is not in ~web.Scope()~.
  22. Video Tutorial (<https://www.youtube.com/watch?v=UPuBvVRhUr0>)
  23. `),
  24. Markdown(`
  25. ### Use PlaidForm
  26. The main use of PlaidForm is to submit one form which is inside another form, and the two forms are completely independent forms.
  27. In the following example, each color represents a completely separate form. The ~Material Form~ contains the ~Raw Material Form~. You can submit the ~Raw Material Form~ to the server first. After receiving it, server will save the ~Raw Material data~ and return the ~ID~.
  28. In this way, you can submit ~Raw Material ID~ directly in the ~Material Form~.
  29. For example:
  30. `),
  31. ch.Code(generated.WebScopeUsePlaidFormSample1).Language("go"),
  32. utils.Demo("Web Scope Use PlaidForm", e00_basics.WebScopeUsePlaidFormPagePath, "e00_basics/web-scope.go"),
  33. Markdown(`
  34. Use ~web.Scope().VSlot("{ plaidForm }")~ to determine the scope of a form.
  35. `),
  36. ).Title("Scope Component").
  37. Slug("basics/scope-component")