Vuejs2 打印数据变量

Vuejs2 打印数据变量,vuejs2,Vuejs2,我正在尝试打印data()变量。我没有得到HTML模板中的输出 <template> <h3>{{app_skills}}</h3> <!-- I am not getting value here --> </template> <script> export default { name: "leftbar", data() { return

我正在尝试打印
data()
变量。我没有得到HTML模板中的输出

<template>
    <h3>{{app_skills}}</h3>   <!-- I am not getting value here -->
</template>

<script>
    export default {
        name: "leftbar",
        data() {
            return {
                app_skills: '',
            }
        },
        methods : {
            fetchskills (url) {
                url = '/skills';

                axios.get(url)
                    .then(response => {
                        this.app_skills = response.data.skills;
                        console.log(this.app_skills) // I am getting value here
                    })
                    .catch(error => {
                        console.log(error);
                    });
            }
        },
        mounted() {
            this.fetchskills();
        }
    }
</script>

{{app_skills}}
导出默认值{
名称:“leftbar”,
数据(){
返回{
app_技能:'',
}
},
方法:{
获取技能(url){
url='/skills';
获取(url)
。然后(响应=>{
this.app_skills=response.data.skills;
console.log(this.app\u skills)//我在这里得到了价值
})
.catch(错误=>{
console.log(错误);
});
}
},
安装的(){
这是fetchskills();
}
}

我尝试时,您的代码完全按照预期工作(进行了一些与环境相关的更改):


{{app_skills}}
从“axios”导入axios;
导出默认值{
名称:“leftbar”,
数据(){
返回{
app_技能:'',
}
},
方法:{
获取技能(url){
url='1〕https://dns.google.com/resolve?name=example.com';
获取(url)
。然后(响应=>{
this.app_skills=response.data;
console.log(this.app\u skills)//我在这里得到了价值
})
.catch(错误=>{
console.log(错误);
});
}
},
安装的(){
这是fetchskills();
}
}

我所做的更改包括axios库、更改要从中提取的URL以及更改
response.data
键以提取。一切正常。也许您周围代码中的其他地方有问题?

应用程序技能的数据类型是什么?如果您在得到响应时
console.log(this)
,这是否会像预期的那样吐出Vue组件?谢谢@JohnEllmore的回复<代码>应用程序技能是一个字符串。我不明白你的第二个问题。谢谢。添加行
console.log(这个)就在您现有的
console.log(this.app\u skills)
语句之后。它印的是什么?谢谢@JohnEllmore。我明白了。谢谢。谢谢@John Elllmore。我在另一个存储库中使用了相同的代码,效果很好。我花了几个小时试图找出这个问题,但失败了。谢谢
<template>
    <h3>{{app_skills}}</h3>   <!-- I am not getting value here -->
</template>

<script>
    import axios from 'axios';
    export default {
        name: "leftbar",
        data() {
            return {
                app_skills: '',
            }
        },
        methods : {
            fetchskills (url) {
                url = 'https://dns.google.com/resolve?name=example.com';

                axios.get(url)
                    .then(response => {
                        this.app_skills = response.data;
                        console.log(this.app_skills) // I am getting value here
                    })
                    .catch(error => {
                        console.log(error);
                    });
            }
        },
        mounted() {
            this.fetchskills();
        }
    }
</script>