Javascript Vuejs调用其他组件';带参数的s方法

Javascript Vuejs调用其他组件';带参数的s方法,javascript,vue.js,vue-component,Javascript,Vue.js,Vue Component,我有两个组件,第一个用于上传文件,第二个用于显示文件。在我的上传组件中,我想调用预览组件并添加一个参数,以便预览组件中的方法使用上传组件中创建的值 到目前为止,我已经做到了: UploadComponent.vue <template> … <button @click="upload"></button> <preview-component :url="this.location"></preview-compon

我有两个组件,第一个用于上传文件,第二个用于显示文件。在我的上传组件中,我想调用预览组件并添加一个参数,以便预览组件中的方法使用上传组件中创建的值

到目前为止,我已经做到了:

UploadComponent.vue

<template>
    …
    <button @click="upload"></button>
    <preview-component :url="this.location"></preview-component>
</template >

<script>
import PreviewComponent from '@/js/components/PreviewComponent';

export default {
    components: {
        'preview-component': PreviewComponent
    },

    props: ['url'],

    data () {
        return {
            // ...
            location: ''
        }
    },

    methods: {
        upload() {
            // ... upload stuff then update the global var location
            this.location = response.data.location;
        },
    }

}
</script>

…
从“@/js/components/PreviewComponent”导入PreviewComponent;
导出默认值{
组成部分:{
“预览组件”:预览组件
},
道具:['url'],
数据(){
返回{
// ...
位置:“”
}
},
方法:{
上传(){
//…上传资料,然后更新全局变量位置
this.location=response.data.location;
},
}
}
这是我的预览组件:

<template>
    <div id="body">
        ///...
    </div>
</template>

<script>
export default {
    props: ['url'],

    methods: {
        loadPdf (url) {
            //
        },
    }    
}
</script>

///...
导出默认值{
道具:['url'],
方法:{
加载PDF(url){
//
},
}    
}

到目前为止,我得到的错误是url没有定义,因此它实际上没有将url从UploadCOmponent发送到PreviewComponent,我如何发送它?

您的
UploadCOmponent
模板中有一个忍者


它应该是
你在
上传组件的模板中得到了一个忍者
这个


它应该是

你好,谢谢,但我仍然在v-on处理程序中遇到这个错误
app.js:7989[Vue warn]:错误:“错误:无效的参数对象:需要.data、.range或.url”app.js:9252错误:无效的参数对象:需要.data、.range或.url
它似乎与您正在使用的一个外部组件有关。不是vue relatedHi谢谢,但我仍然在v-on处理程序中收到此错误:错误:无效参数对象:需要.data、.range或.url“app.js:9252错误:无效参数对象:需要.data、.range或.url
它似乎与您正在使用的某个外部组件有关。Not vue relatedparent component使用
:url=“location”
将道具传递给子组件,并且在使用
this.url的方法中的子组件访问道具中使用
:url=“location”
将道具传递给子组件,在使用
this.url的方法中的子组件访问道具中使用
this.url