如何momentjs为用户实时更新相对时间?
我计算过:
computed: {
ago() {
return moment().fromNow();
},
}
Run Code Online (Sandbox Code Playgroud)
当我在组件中使用时:
<span class="text-muted pr-2" v-text="ago"></span>
Run Code Online (Sandbox Code Playgroud)
我得到静态文本:a few seconds ago,如何在不重新加载页面的情况下更新此文本?我想看:a minute ago,atwo minutes ago等。
我如何为用户实时执行此操作?
当 prop 更新时如何调用函数?
父容器:
<div>
<Maintable :type="typeRef" :country="countryRef" />
</div>
Run Code Online (Sandbox Code Playgroud)
子容器:
export default{
props: ['type'],
setup(props)
{
watch(props.type, () => {
console.log('hello')
})
}
Run Code Online (Sandbox Code Playgroud)
此代码收到错误:无效的监视源...我如何侦听道具的更新?
希望有人可以帮助我!:-)
我试图用 开始一个vue3项目vuecli,但是当我添加时vuetify,出现错误,而使用时一切正常vue2。它说
错误:您不能在没有路径的集合上调用“get”。相反,首先检查“长度”属性以验证至少存在 1 个路径。

有人有同样的问题,需要一些解决方案,谢谢。
我正在尝试确定我的 Nuxt 应用程序 (2.14.0) 是使用 Vue 2 还是 Vue 3,但我不知道。我已经潜入node_modules并查看了我的锁定文件,但不能确定。我认为它只使用了 Vue 2——特别是vue "^2.6.12——基于我在锁定文件中所能知道的。
有谁知道 Nuxt 在 2.14.0 版本中使用的是哪个版本的 Vue?我尝试通读此问题以更好地了解 Vue 3 何时/是否已在 Nuxt.js 中引入和公开发布,但听起来 Vue 3 并未包含在任何 Nuxt.js 版本中。
输入如此简单
<input ref="input" class="terminal-input" autofocus
v-model="message" type="submit" @submit.prevent="printToConsole"/>
Run Code Online (Sandbox Code Playgroud)
添加后type="submit"我无法再输入内容。它只是变成了一个按钮!所以我找到了一个解决方案,只需制作一个表单,添加一个按钮(使其提交)并隐藏该按钮。
<form>
<input ref="input" class="terminal-input" autofocus v-model="message"/>
<q-btn type="submit" @click="printToConsole" v-show="false"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式做到这一点,但只需要输入吗?(所以没有隐藏按钮的东西)
在定义自定义事件时, Vue 鼓励我们通过以下emits选项在组件上定义发出的事件:
app.component('custom-form', {
emits: ['inFocus', 'submit']
})
Run Code Online (Sandbox Code Playgroud)
使用 Vue 3 的组合 API,当一个独立的组合函数发出自定义事件时,是否可以在组合函数中定义这些?
我使用Vue 2 Composition API,并希望在我的方法中从 Vue Router 访问路由参数setup()。
如Vue Router 文档中所述:
因为我们无权访问 的
this内部setup,所以我们无法直接访问this.$routerorthis.$route。相反,我们使用该useRouter函数:Run Code Online (Sandbox Code Playgroud)import { useRouter, useRoute } from 'vue-router' export default { setup() { const router = useRouter() const route = useRoute() function pushWithQuery(query) { router.push({ name: 'search', query: { ...route.query, }, }) } }, }
不幸的是,此方法在 Vue 2 的 Vue Router 中不可用。这里有哪些选项以及如何使用 Vue 2 Composition API 访问我的路由参数?
TypeScript 新手。我正在尝试设置状态但收到此错误。
错误:'string' only refers to a type, but is being used as a value here.
const state = reactive({
user: {
uid: "",
provider: string[],
}
});
const user = auth.currentUser;
if (user != null) {
state.user.uid = user.uid || "";
user.providerData.forEach(function(profile) {
state.user.provider.push({
providerId: profile.providerId,
uid: profile.uid,
})
});
}
Run Code Online (Sandbox Code Playgroud) 尝试在具有组合 API 的组件中实现 vue-i18n。我希望能够在 onMounted 挂钩内设置一些翻译消息。在选项 api 中,我会使用this.$i18n.setLocaleMessage(locale, messages).
但是,this在组合 API 的 Setup() 方法中不可用。因此,当我尝试上述操作时,它给了我未定义的信息。我可以通过将 i18n 导入到组件中来做到这一点:
import { useI18n } from 'vue-i18n'然后创建它的一个实例var i18n = useI18n({}), i18n.setLocaleMessage(),但我更喜欢像第一个这样的单行解决方案。
有没有一些简单的方法如何在 nuxtjs asyncData 函数中读取 POST 请求参数?
下面是一个例子:
表单.vue:
<template>
<form method="post" action="/clickout" target="_blank">
<input type="hidden" name="id" v-model="item.id" />
<input type="submit" value="submit" />
</form>
</template>
Run Code Online (Sandbox Code Playgroud)
将以前的表单路由提交到以下 nuxt 页面:
Clickout.vue
async asyncData(context) {
// some way how to get the value of POST param "id"
return { id }
}
Run Code Online (Sandbox Code Playgroud) vue.js ×9
vuejs3 ×7
vuejs2 ×4
javascript ×2
nuxt.js ×2
firebase ×1
html ×1
momentjs ×1
typescript ×1
vue-i18n ×1
vue-props ×1
vue-router ×1
vue-router4 ×1
vuetify.js ×1