Skip to content

我想在md文件中引用config.js定义的全局变量,应该怎么做? #1622

Closed Answered by Mister-Hope
Louis-XIV asked this question in Q&A
Discussion options

You must be logged in to vote

.vuepress/client.js:

import { defineClientConfig } from 'vuepress/client'


export default defineClientConfig({
  enhance({ app }) {
    Object.defineProperties(app.config.globalProperties, {
      $a: {
        get() {
          return '123'
        },
      },
    })
  }
})

In markdown file:

${{ $a }}

You will get 123 in render result.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Louis-XIV
Comment options

@Mister-Hope
Comment options

Answer selected by Louis-XIV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants