Load form data via REST in vue-form-generator

I am creating a form that needs to dynamically retrieve data using a JSON request that must be completed when the form loads. I do not see a way to load this data. Can anybody help?

JSON calls are made through vue-resource, and forms are generated through vue-form-generator.

export default Vue.extend({
  template,

  data() {
    return {
      model: {
        id: 1,
        password: 'J0hnD03!x4',
        skills: ['Javascript', 'VueJS'],
        email: 'john.doe@gmail.com',
        status: true
      },

      schema: {
        fields: [
          {
            type: 'input',
            inputType: 'text',
            label: 'Website',
            model: 'name',
            maxlength: 50,
            required: true,
            placeholder: companyList
          },
        ]
      },

      formOptions: {
        validateAfterLoad: true,
        validateAfterChanged: true
      },
      companies: []
    };
  },

  created(){
    this.fetchCompanyData();
  },

  methods: {
    fetchCompanyData(){
      this.$http.get('http://echo.jsontest.com/key/value/load/dynamicly').then((response) => {
        console.log(response.data.company);
        let companyList = response.data.company; // Use this var above
      }, (response) => {
        console.log(response);
      });
    }
  }

}); 
+4
source share
1 answer

You can simply assign the this.schema.fields.placeholdervalue returned by the API, for example:

  methods: {
    fetchCompanyData(){
      this.$http.get('http://echo.jsontest.com/key/value/load/dynamicly').then((response) => {
        console.log(response.data.company);
        this.schema.fields.placeholder = response.data.company
      }, (response) => {
        console.log(response);
      });
    }
  }
+3
source

Source: https://habr.com/ru/post/1665132/


All Articles