C# 我无法在本地使用VUE js

C# 我无法在本地使用VUE js,c#,vue.js,C#,Vue.js,//这是来自本地的,它是json对象 { 身份证号码:654321, 姓名:Mohd, 年龄:22 }, { Id:102030, 姓名:法赫德, 年龄:18 } //这是我的代码不起作用 var app = new Vue({ el: '#app', data: { socialId: '', person: '' }, watch: { socialId: function() { this.person = '' if (th

//这是来自本地的,它是json对象 { 身份证号码:654321, 姓名:Mohd, 年龄:22 }, { Id:102030, 姓名:法赫德, 年龄:18 } //这是我的代码不起作用

var app = new Vue({
  el: '#app',
  data: {
    socialId: '',
    person: ''
  },
  watch: {
    socialId: function() {
      this.person = ''
      if (this.socialId.length == 6) {
        this.lookupsocialId()
      }
    }
    },

  methods: {
    lookupsocialId: _.debounce(function() {
      var app = this
      app.person = "Searching..."
      axios.get('http://localhost:49999/api/people/' + app.socialId)
            .then(function (response) {
              app.person = response.data.Name + ', ' + response.data.Age
            })
            .catch(function (error) {
              app.person = "Invalid Zipcode"
            })
    }, 500)
  }
})
但我用过这个,效果很好 json对象{ 国家:美国, 州:纽约, 城市:斯克内克塔迪 }


为什么我在本地使用它时不起作用

您需要将结果转换为文件中的json,在使用axio response.json之后,您可以尝试以下代码

var app = new Vue({
  el: '#app',
  data: {
    socialId: '',
    person: ''
  },
  watch: {
    socialId: function() {
      this.person = ''
      if (this.socialId.length == 6) {
        this.lookupsocialId()
      }
    }
    },

  methods: {
    lookupsocialId: _.debounce(function() {
      var app = this
      app.person = "Searching..."
      axios.get('http://localhost:49999/api/people/' + app.socialId)
            .then(function (response) {
              app.person = response.data.Name + ', ' + response.data.Age
            })
            .catch(function (error) {
              app.person = "Invalid Zipcode"
            })
    }, 500)
  }
})
导出默认值{ 资料{ 返回{ 标题:表格登记册, formdata:{}, 信息:, 成功率:0, } }, 方法:{ 登记册{ 这是axios。posthttp://localhost:8888/form-注册,this.formdata.thenresponse=>{ console.logresponse; ifresponse.data.success>0{ this.message=您注册成功; this.success=response.data.success; } 否则{ this.message=注册失败; this.success=response.data.success; } }; }, } } //构造json [ { 姓名:abc 年龄:34 }, { 姓名:abc 年龄:34 } ]
如果使用php,您可以在phpClarify中回显json_编码,从而明确您的要求。如果您询问为什么调用本地主机终结点不起作用,请调试本地终结点。在进行XHR调用之前进行单元测试。解释什么不起作用。