分享:nuxt注入 $root 和 context

Vue全局注入实践
本文介绍如何在Vue应用中全局注入函数或属性值,包括在Vue实例、context及Vuex store中进行注入的方法,以便在整个应用中方便地使用这些资源。

注入 $root 和 context

有时您希望在整个应用程序中使用某个函数或属性值,此时,你需要将它们注入到Vue实例(客户端),context(服务器端)甚至 store(Vuex)。按照惯例,新增的属性或方法名使用$作为前缀。

ERROR in src/modules/data-map/data-table/assets-table-detail/blood/views/g6-blood-table.vue:37:14 TS2339: Property '$axios' does not exist on type 'CombinedVueInstance<Vue, object, object, object, Record<never, any>>'. 35 | if (isInit) { 36 | request = () => > 37 | vm.$axios | ^^^^^^ 38 | .$get(tableLineageBlood(tableId), { 39 | params: { 40 | upstreamLevel: 1, ERROR in src/modules/data-map/data-table/assets-table-detail/blood/views/g6-blood-table.vue:44:19 TS7006: Parameter 'res' implicitly has an 'any' type. 42 | }, 43 | }) > 44 | .then(res => res.payload) | ^^^ 45 | } else { 46 | request = () => 47 | vm.$axios ERROR in src/modules/data-map/data-table/assets-table-detail/blood/views/g6-blood-table.vue:47:14 TS2339: Property '$axios' does not exist on type 'CombinedVueInstance<Vue, object, object, object, Record<never, any>>'. 45 | } else { 46 | request = () => > 47 | vm.$axios | ^^^^^^ 48 | .$get(lineageBlood, { 49 | params: { 50 | nodeId: data.nodeId, ERROR in src/modules/data-map/data-table/assets-table-detail/blood/views/g6-blood-table.vue:55:19 TS7006: Parameter 'res' implicitly has an 'any' type. 53 | }, 54 | }) > 55 | .then(res => res.payload) | ^^^ 56 | } 57 | return request().then((payload: any) => { 58 | return { ERROR in src/modules/data-map/data-table/assets-table-detail/blood/views/g6-blood-table.vue:112:22 TS2339: Property '$router' does not exist on type 'CombinedVueInstance<Vue, object, object, object, Record<never, any>>'. 110 | value: data.dataCollectSuccess 111 | ? `<a class="tooltip-value primary" href="${ > 112 | vm.$router.resolve(`/data-map/data-table/${data.tableId}`).href | ^^^^^^^ 113 | }"> ${data.tableName} </a>` 114 | : data.tableName, 115 | }, FATAL Nuxt build error 09:02:49 at WebpackBundler.webpackCompile (node_modules/@nuxt/webpack/dist/webpack.js:1888:21) at async WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:1853:5) at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:249:5) at async ensureBuild (node_modules/@nuxt/cli/dist/cli-generate.js:117:3) at async Object.run (node_modules/@nuxt/cli/dist/cli-generate.js:234:7) at async NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:356:7) ╭─────────────────────────────╮ │ │ │ ✖ Nuxt Fatal Error │ │ │ │ Error: Nuxt build error │ │ │ ╰─────────────────────────────╯
08-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值