partial-refresh-with-portal.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. . "github.com/theplant/htmlgo"
  9. )
  10. var PartialRefreshWithPortal = Doc(
  11. Markdown(`
  12. As said before, The results of an ~web.EventFunc~ could be:
  13. - Go to a new page
  14. - Reload the whole current page
  15. - Refresh part of the current page
  16. We have covered two. Now let's demonstrate refresh part of the current page:
  17. `),
  18. ch.Code(generated.PartialUpdateSample).Language("go"),
  19. utils.Demo("Partial Update", e00_basics.PartialUpdatePagePath, "e00_basics/partial-update.go"),
  20. Markdown(`
  21. ~web.Portal().Name("part1")~ Place a placeholder inside you page, and append ~web.PortalUpdate~ to ~er.UpdatePortals~ to update the portal with that name.
  22. Multiple portal can be updated at the same time.
  23. `),
  24. utils.Anchor(H2(""), "Load Portal in separate AJAX request"),
  25. Markdown(`
  26. With ~web.Portal~, We can also load the portal with a separate AJAX request after page load.
  27. It is useful for the type of the content is not that important to the page, But load them are
  28. quite heavy. Like related products of a product detail page of a ECommerce site.
  29. `),
  30. ch.Code(generated.PartialReloadSample).Language("go"),
  31. utils.Demo("Partial Reload", e00_basics.PartialReloadPagePath, "e00_basics/partial-reload.go"),
  32. Markdown(`
  33. It is not only load the portal in separate AJAX request, Also you can reload it with ease ~er.ReloadPortals = []string{"related_products"}~ in an event func.
  34. Under the hood, We use Vue's [Dynamic & Async Components](https://vuejs.org/v2/guide/components-dynamic-async.html), to load Go generated html (vue runtime templates)
  35. from the server and mount those vue components into the page. It works the same way for reload the whole page, push state page switch, and refresh part of the current page.
  36. `),
  37. ).Title("Partial Refresh with Portal").
  38. Slug("basics/partial-refresh-with-portal")