如何避免v-text-field发出输入事件?

时间:2019-05-18 09:39:04

标签: vuejs2 vuetify.js

由于性能限制,我正在尝试为v-model.lazy模拟v-text-field

我尝试过:

<v-text-field :value="p.name" @change="v => p.name = v" :data-vv-name="'name'+p.id" v-validate="'required|max:255'" :error-messages="errors.collect('form'+p.id+'.'+'name'+p.id)" :counter="255" :label="$t('property.name')" required maxlength="255" :data-vv-as="' '" v-else></v-text-field>

但是我一直在获得所有按键和输入信号,这引起了很大的滞后: enter image description here

如果我将输入与v-model.lazy一起使用,它会按预期工作,但是我无法使用v-text-field实现相同的功能。

这些事件是否应该使用prevent.default?

1 个答案:

答案 0 :(得分:0)

添加private FusedLocationProviderClient mFusedLocationProviderClient; private void getDeviceLocation() { mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); try { if ( ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ) { return; } } catch (Exception e) { e.printStackTrace(); } final Task location = mFusedLocationProviderClient.getLastLocation(); Log.d("Works to here:","here"); location.addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if ( task.isSuccessful() ) { Location currentLocation = (Location) task.getResult(); double lat = currentLocation.getLatitude(); double lon = currentLocation.getLongitude(); Log.d("workes to here:",String.valueOf(lat)); addMarker(lat, lon); final LatLng sydney = new LatLng(lat, lon); mapFragment.mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { googleMap.addMarker(new MarkerOptions().position(sydney)); } }); } } }); } data-vv-delay="1000"而不是:value="p.name" @change="v => p.name = v"可以大大改善延迟。这将延迟该字段的验证。

真正的解决方案需要v-model才能在Vuetify的v-model.lazy上运行,但情况并非如此。