我最近将typescript添加到我的vue项目中,每次访问props 或数据中的值时,我都会收到这个错误
37:46 Property 'activity' does not exist on type '{ props: { activity: { type: ObjectConstructor; required: boolean; }; }; methods: { formatDistance: (distance: number, setting_unit: string) => string; }; mounted: () => void; }'.
35 | },
36 | mounted: function () {
> 37 | var activitymap = L.map('map' + this.activity['activity']['id']).setView([51.505, -0.09], 13)
| ^
这是我的props
props: {
activity: {
type: Object,
required: true
}
},
这就是它正在使用的方法
mounted: function () {
var activitymap = L.map('map' + this.activity['activity']['id']).setView([51.505, -0.09], 13)
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: '<a href="https://www.openstreetmap.org/">OpenStreetMap</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: process.env.VUE_APP_MAPBOX_KEY
}).addTo(activitymap)
var gpxGroup = new L.FeatureGroup();
activitymap.addLayer(gpxGroup);
omnivore.gpx(this.activity['activity']['activity_log_url']).addTo(gpxGroup).on('ready',
function () {
activitymap.fitBounds(gpxGroup.getBounds());
}
)
}
是什么导致了这个问题?