


What should I do if the Vue reference datepicker plug-in cannot monitor the value of the datepicker input box?
This article mainly introduces the solution to the problem that Vue cannot monitor the value of the datepicker input box when using the third-party datepicker plug-in. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
1. Background
The third-party datepicker plug-in is used in the Vue project. After selecting the date, Vue cannot detect the datepicker input box. Changes
<label class="fl">日期:</label> <p class="input-wrapper fr"> <input class="daterangepicker" ref="datepicker" v-model="dateRange"/> <a href="javascript:;" rel="external nofollow" ></a> </p> export default { data() { return { dateRange: '' } }, watch: { dateRange(newVal, oldVal) { console.log(newVal) // 选择日期后无法监听dateRange的改变 } } }
2. Analysis
Searching for information found that Vue is actually unable to monitor data changes caused by third-party plug-ins. So the above method doesn't work. However, Vue provides us with a method that can convert any data into data that can be monitored by Vue, which is: vm.$set.
3. Solution
Take the datepicker I use as an example (jquery-daterangepicker)
data() { return { date: '', beginDate: '', endDate: '' } }, mounted () { $('.daterangepicker').dateRangePicker({ autoClose: true, format: 'YYYY-MM-DD' }).bind('datepicker-change', this.setDate) //插件自带方法,选择日期后触发回调 }, methods: { setDate() { let datepicker = this.$refs.datepicker //这一步是关键,具体说明可以参见vue api手册 this.$set(this.date, 'beginDate', datepicker.value) this.$set(this.date, 'endDate', datepicker.value) this.beginDate = this.date.beginDate.slice(0, 11) this.endDate = this.date.endDate.slice(-10) } }, watch: { // 这里就可以监听数据变化啦,可以愉快的选择日期了! beginDate(newVal, oldVal) { this.$emit( 'beginDateChange', newVal ) }, endDate(newVal, oldVal) { this.$emit( 'endDateChange', newVal ) } }
Related recommendations:
jQuery UI date picker Datepicker detailed explanation
Detailed explanation of how to use the JS control bootstrap datepicker (picture)
phpCall My97DatePicker_PHP Tutorial
The above is the detailed content of What should I do if the Vue reference datepicker plug-in cannot monitor the value of the datepicker input box?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to monitor the scrolling of an iframe requires specific code examples. When we use the iframe tag to embed other web pages in a web page, sometimes we need to perform some specific operations on the content in the iframe. One of the common needs is to listen for the scroll event of the iframe so that the corresponding code can be executed when the scroll occurs. The following will introduce how to use JavaScript to monitor the scrolling of an iframe, and provide specific code examples for reference. Get the iframe element First, we need

If a phone is implanted with software and monitored, the phone can be deactivated by restarting the phone, checking phone settings, deleting applications, using security software, and contacting the phone manufacturer or application developer. Detailed introduction: 1. Restart the phone, press and hold the power button of the phone until the startup screen appears, and then select the "Restart" option; 2. Check the phone settings to ensure that no unauthorized applications are running; 3. Delete the application and Search and delete unauthorized applications in the app store; 4. Use security software. Security software can help you detect and block potentially dangerous applications, etc.

The reasons why Oracle cannot find the monitor: 1. The monitor program has not been started, causing the connection to fail; 2. The monitor program is configured incorrectly. Make sure the port number and other related configurations are correct by checking the configuration of the parameter file; 3. There is a firewall setting problem, check the firewall Configuration, make sure the relevant ports are open; 4. Host name resolution issues, check the configuration of host name resolution, and make sure the host name resolution is correct; 5. The listening program crashes or closes abnormally, check the log file of the listening program; 6. Network connection Problem due to network failure, network configuration error or network overload.

How to solve Vue error: Unable to use v-on to listen to keyboard events correctly. As a popular front-end framework, Vue.js can help us build efficient, flexible and maintainable web applications. Among them, Vue provides the v-on instruction to monitor DOM events to facilitate us to handle user operations. However, when using v-on to monitor keyboard events, we sometimes encounter some errors that prevent us from using this function correctly. This article will walk you through this problem and provide some code examples. Check Vue version

Sorry, I can't provide a direct code example. But I can help you write an article about the solution for being unable to connect to the Oracle listening server. The length of the article is limited to 1500 words. The following is the content of the article: Solution to the inability to connect to the Oracle listening server. When using the Oracle database, sometimes you will encounter the problem of being unable to connect to the Oracle listening server. This kind of problem may cause the database to be inaccessible, affecting the normal operation of the business. When faced with this situation, we need

In Vue, we can use the v-on directive to listen for events on DOM elements. However, in actual development, we may need to monitor more complex events, such as single click, double click, long press, etc. At this time, using v-on seems to be somewhat inadequate. So, how to implement monitoring of these events in Vue? This article will explain it to you in detail. 1. Click event monitoring Click events are very common in applications. Vue provides the v-on:click abbreviation @click

Use the http.Server function to create an HTTP server object that can listen to the specified address and port. In the Go language, we can use the http.Server function to create an HTTP server object that can listen to the specified address and port. The http.Server function receives a parameter of type http.Handler, that is, we can pass in our custom handler to handle HTTP requests. Below is a sample code showing how to use http.Serv

How can PHP continuously listen to Redis message subscriptions and send push notifications? With the rapid development of the Internet, real-time notifications have become a necessary feature of many applications. As a high-performance key-value storage database, Redis's publish and subscribe functions can well meet this demand. This article will introduce how to use PHP to continuously monitor Redis messages and send messages to users through push notifications. Before starting, you need to make sure that the Redis extension has been installed. You can do this by running the following command
