stacklens / dusai-blog

杜赛的博客的评论区。详情见 Issue。
2 stars 0 forks source link

article/134/ #118

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Django-Vue搭建个人博客:组合式API - 杜赛的博客

https://www.dusaiphoto.com/article/134/

mike-egg123 commented 2 years ago

有个问题哈,为什么不可以在scr/composables/formattedTime.js中这样写呢?

export default function formattedTime () {
  const formatted_time = (iso_date_string) => {
    return formatted(iso_date_string)
  }

  return {
    formatted_time
  }
}

function formatted (iso_date_string) {
  const date = new Date(iso_date_string);
  return date.toLocaleDateString();
}

然后在ArticleList.vuesetup()中这样调用呀:const formatted_time = formattedTime(); 我这样写会报这个错:

Uncaught (in promise) TypeError: $setup.formatted_time is not a function
    at eval (ArticleList.vue?64e5:21:1)
    at renderList (runtime-core.esm-bundler.js?5c40:2884:1)
    at Proxy.render (ArticleList.vue?64e5:2:1)
    at renderComponentRoot (runtime-core.esm-bundler.js?5c40:896:1)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js?5c40:5651:1)
    at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:185:1)
    at instance.update (runtime-core.esm-bundler.js?5c40:5694:1)
    at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:155:1)
    at flushJobs (runtime-core.esm-bundler.js?5c40:396:1)

(保证不是命名错误这种低级bug)