vuejs:导入的JSON文件上的不正确值[VUE:2.6.12]

发布于 2025-02-08 12:09:35 字数 631 浏览 2 评论 0原文

我正在使用vuejs2 [版本2.6.12]。试图导入本地JSON文件。

JSON文件内容:{“名称”:“ John”,“ Age”:30}

import json from '../static/data.json'

我正在通过CLI构建“ NPM Run Build”项目。

我现在正在更改JSON文件内容: 新的JSON文件内容:{“ name”:“ doe”,“ age”:30}

现在我要转到“ dist”文件夹并打开index.html文件。我在模板上使用“名称”,并看到“名称”为“约翰”

我的组件数据:

    export default{
      name: 'App',
      data () {
        return {
           name: json.name,
      },
      mounted () {
        //incorrect data. i have changed the name to "Doe", but still it is showing "John"
        console.log(this.name) //logging John
      }
    }

I am using vuejs2 [version 2.6.12]. Trying to import a local JSON file.

JSON File content: {"name":"John", "age":30}

import json from '../static/data.json'

I am building the project by "npm run build" from CLI.

I am changing the JSON file content now:
New JSON File content: {"name":"Doe", "age":30}

Now I am Going to the "dist" folder and opening the index.html file. I am using the "name" on my template and seeing the "name" to be "John"

My Component data:

    export default{
      name: 'App',
      data () {
        return {
           name: json.name,
      },
      mounted () {
        //incorrect data. i have changed the name to "Doe", but still it is showing "John"
        console.log(this.name) //logging John
      }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2025-02-15 12:09:35

创建构建时,导入的JSON文件也将与JavaScript混合。

如果您在构建项目后更改JSON文件中的名称,则将获得新的值。

尝试一下,
更改JSON中的名称并创建构建。

When you create the build, imported json file also will mix with javascript.

If you change the name in json file after building the project, you won't get new value.

Try this instead,
Change the name in json and create the build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文