vue.jsvuejs2laravel-spark

how to pass object vuejs


In My laravel + Spark + Vue js project, I have used https://github.com/Vanthink-UED/vue-core-image-upload, They have code like

export default {
props:{
 cropBtn: {
    type: Object,
    default: function() {
      return {
        ok: '保存',
        cancel: '取消',
      }
    }
  }
}

As per their documentationm, If you want to change button text then do following

cropBtn Object {ok:'Save','cancel':'Give Up'} the text of crop button

I have used like

<vue-core-image-upload 
                      v-bind:class="['pure-button','pure-button-primary','js-btn-crop']" 
                      v-bind:crop="true" url="/process-image" 
                      extensions="png,gif,jpeg,jpg" 
                      cropBtn="[{ok: 'Save',cancel: 'Cancel'}]"                     
                      v-on:imageuploaded="imageuploaded">
                    </vue-core-image-upload>

and

v-bind:cropBtn="items"

js file

module.exports = {
prop:['cropBtn'],
data() {        
     return {
         items: [{
                    ok: 'Save',
                    cancel: 'Cancel',
                  }],
                  cropBtn: {
                            type: Object,
                            default: function() {
                              return {
                                ok: 'Save',
                                cancel: 'Cancel',
                              }
                            }
                          },

        src: 'http://img1.vued.vanthink.cn/vued0a233185b6027244f9d43e653227439a.png'            
    };
}
};

But it is not working. I am getting same default Chinese value.

Any suggestions what can be the solution?


Solution

  • You need to use kebab-case when passing props that are declared in camel case and you must use v-bind or the shorthand : when passing javascript objects through props:

    <vue-core-image-upload :crop-btn="{ok: 'Save',cancel: 'Cancel'}"                     ></vue-core-image-upload>
    

    see: https://v2.vuejs.org/v2/guide/components.html#camelCase-vs-kebab-case