跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Vue.js] 请教 Vue3 的 defineComponent 函数使用

发表于

各位好,我又来请教个 Vue3 的问题,标签页系统使用 defineComponent 创建组件,实现刷新功能。由于组件需要缓存,使用了 keepalive ,于是用 pinia 存储组件的 name 属性,所以创建时在 name 加上时间戳将其表示唯一。

GitHub 地址

createNode.js的部分代码片段如下,本意是想看下创建组件时的时间戳:

function getTimeStamp() {
  let timeNow = Date.now();
  console.log("create: ", timeNow);
  return timeNow;
}

export function createNameComponent(component) {
  return () => {
    return new Promise((resolve) => {
      component().then((comm) => {
        const tempComm = defineComponent({
          name: (comm.default.name || "vueAdminBox") + "_" + getTimeStamp(),
          props: comm.default.props || {},
          ...

当前实现效果如下:

20240919 223831

可以看到,组件只有第一次打开时会触发getTimeStamp函数,关闭再打开就不会重新获取时间戳了。

我期望每次打开标签页都是不同的时间戳,有老哥遇到这个问题吗?

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.