我有以下两个组件(父组件和子组件)
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Index.vue (Parent)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 _GetShipment.vue (Child)\nRun Code Online (Sandbox Code Playgroud)\n在Index.vue我尝试使用 Office.js\ 的 getAsync 获取电子邮件正文的内容:
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Index.vue (Parent)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 _GetShipment.vue (Child)\nRun Code Online (Sandbox Code Playgroud)\n上面检查电子邮件正文内容以查看是否存在正则表达式匹配。如果存在,它将把匹配项添加到数组中shipments。
目前,如果仅找到一个匹配项,则该匹配项将在名为 的子组件中呈现_GetShipment:
<script>\nimport Shipment from \'./_GetShipment.vue\';\nimport { ref, defineComponent } from \'vue\';\n\n\nexport default defineComponent({\n setup() {\n const shipments = ref([]);\n\n Office.context.mailbox.item.body.getAsync(\n "text",\n function (result) {\n if (result.status === Office.AsyncResultStatus.Succeeded) {\n let matches = result.value.match(/S\\w{3}\\d{8,9}/ig);\n if(matches){\n shipments.value = matches;\n }\n }\n }\n );\n\n return {\n shipments,\n }\n },\n components: {\n Shipment,\n },\n})\n</script>\n\n<template>\n …Run Code Online (Sandbox Code Playgroud) 我正在 github 页面(vite、vue3、typescript)上开发一个小项目,并且在使用 vue-i18n 进行插值时遇到问题。我一直试图在其他地方找到同样的问题,但我一直无法找到这样的例子。我想知道最近是否有一些我误解的变化。这是我遇到的问题:作为示例,我希望使用 i18n 显示此消息。
\nHello World\nRun Code Online (Sandbox Code Playgroud)\n所以在我的语言环境 json 文件中我有
\n{ "hello_": "Hello {0}" }\nRun Code Online (Sandbox Code Playgroud)\n在我的模板中我有
\n<p>{{$t(\'hello_\', [\'World\'])}}</p>\nRun Code Online (Sandbox Code Playgroud)\n当我在本地工作时,我得到
\nHello World\nRun Code Online (Sandbox Code Playgroud)\n正如预期的那样。但是,当我构建应用程序并部署 dist 时,我得到了
\nHello {0}\nRun Code Online (Sandbox Code Playgroud)\n我的原始代码将键路径和插值参数作为 props 传递给另一个组件。我尝试直接指定它(如上面的示例所示),还尝试了命名插值"hello_":"Hello {name}",{{$t("hello_", {name: "World"})}}它在开发中也运行良好,但在生产中却不起作用。我尝试过使用 $t 并直接通过导入
import { useI18n } from \'vue-i18n\' \n const\xc2\xa0{\xc2\xa0t\xc2\xa0}\xc2\xa0=\xc2\xa0useI18n({\xc2\xa0useScope:\xc2\xa0\'global\'\xc2\xa0})\nRun Code Online (Sandbox Code Playgroud)\n这是我的packages.json
\nHello World\nRun Code Online (Sandbox Code Playgroud)\n这是我的 vite.config.ts
\n import { dirname, resolve } from \'node:path\'\n import { fileURLToPath, URL } …Run Code Online (Sandbox Code Playgroud) 我正在使用Nuxt 3
我有这样的.env
NUXT_CAPTCHA_KEY=123456
Run Code Online (Sandbox Code Playgroud)
这是nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
public: {
captchaKey: 'some value',
}
},
});
Run Code Online (Sandbox Code Playgroud)
在我的组件login.vue中
我想像这样使用Recaptcha
function login() {
const config = useRuntimeConfig()
console.log('config', config.public.captchaKey);
}
Run Code Online (Sandbox Code Playgroud)
'123456'我认为它必须在控制台中打印
正如文件中所说
但事实并非如此。
它打印'some value'
这是为什么 ?
我正在尝试有一个 getter 来返回我的 pinia 商店的所有状态属性。
export const useFilterStore = defineStore('filterStore', {
state : () : FilterState => ({
variables:[] as string[],
categories:[] as string[]
}),
getters: {
getFilters: (state) => state
},
actions : {}
});
Run Code Online (Sandbox Code Playgroud)
通过这种方式,getFilters 引用自身,在不同情况下生成循环引用,如本组件所示
import { useFilterStore } from './store/filter-store.js'
export default {
name: 'App',
setup() {
const filter = useFilterStore()
JSON.stringify(filter.getFilters) --> cyclic object value
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法直接为整个状态对象设置一个getter?
我想在 Vue 3 中声明一个全局变量,任何组件(以及 main.js 本身)都可以随时更改该变量,并且应该是响应式的。
我的 main.js 文件:
const app = createApp(App);
app.config.globalProperties.$myGlobalVariable = {
content: 'not updated'
};
// simulating something async as an HTTP call
setTimeout(() => {
app.config.globalProperties.$myGlobalVariable.content = 'updated';
console.log(app.config.globalProperties.$myGlobalVariable.content); // updated
}, 2000);
app.mount('#app');
Run Code Online (Sandbox Code Playgroud)
我的组件文件:
<script>
export default {
created() {
setTimeout(() => {
console.log(this.$myGlobalVariable.content)// updated
}, 3000);
}
}
</script>
<template>
<main>
<p>{{ $myGlobalVariable.content }}</p>
</main>
</template>
Run Code Online (Sandbox Code Playgroud)
在我的组件(p元素)内部,我只看到not updated,尽管我的组件的函数setTimeout内部created()证明它已经改变。$myGlobalVariable.content如何获取元素内部更改的值p?
是否可以仅使用 javascript(作为对象)而不是在模板中使用 vue、vue-i18n?
在 src/boot/i18n.js 中
import { boot } from 'quasar/wrappers'
import { createI18n } from 'vue-i18n'
import messages from 'src/i18n'
export default boot(({ app }) => {
const i18n = createI18n({
locale: 'es-CO',
fallbackLocale: 'en-US',
globalInjection: true,
messages
})
// Set i18n instance on app
app.use(i18n)
})
Run Code Online (Sandbox Code Playgroud)
但我创建了一个 src/support/errors 和 utils,以及更多扩展文件,我需要插入消息但可以访问 i18n。
我是西班牙人,是 quasar vue 的初级学生,所以请帮助我
谢谢。
我需要 VueJS 组件中的路由参数。例如中的42example.de/page/42。
// router
// ...
{
path: '/pages/:id',
name: 'pages',
component: () => import('../views/PageView.vue'),
},
// ...
Run Code Online (Sandbox Code Playgroud)
// PageView.vue
<script setup>
import { onMounted } from "vue";
import { ref } from 'vue';
onMounted(async () => {
console.log( $route.params.id );
}
Run Code Online (Sandbox Code Playgroud)
这里我得到错误:
Uncaught (in promise) ReferenceError: $route is not defined。
但在组件的模板中,{{ $route.params.id }}可以进行访问。但我在剧本中需要它。我究竟做错了什么?
javascript vue.js vuejs3 vue-composition-api vue-script-setup
我正在使用最新版本的 Vuelidate 和 Vue 3。有没有办法为内置验证器全局设置错误消息?我在文档中看到这一部分,它说要withMessage在辅助对象上使用该函数,如下所示:
import { required, helpers } from '@vuelidate/validators'
const validations = {
name: {
required: helpers.withMessage('This field cannot be empty', required)
}
}
Run Code Online (Sandbox Code Playgroud)
但这看起来像是每次我们构建规则对象时都需要设置。
我见过这个: Get element height with Vuejs 但根据我的理解,功能组件没有这个关键字。如何获取 vue.js 中 HTML 元素的高度?我来自 React 背景,只会在那里使用 refs,但 vue 中的 refs 似乎不一样。任何想法?
如何使用FormKit(使用 Vue3)进行异步/服务器端验证?不仅在提交时,而且在用户从输入中移除焦点之后。
基本验证示例:
<FormKit
type="text"
label="Number"
validation="required|number|between:20,50"
validation-visibility="live"
help="Enter a number between 20 and 50."
/>
Run Code Online (Sandbox Code Playgroud)
除了文档提到一次异步之外,在任何地方都找不到任何示例或提及。
vuejs3 ×10
vue.js ×7
javascript ×5
vue-i18n ×2
formkit ×1
nuxt.js ×1
nuxtjs3 ×1
office-js ×1
pinia ×1
typescript ×1
validation ×1
vite ×1
vuelidate ×1