Detailed explanation of how to use Vue to load weather components

Detailed explanation of how to use Vue to load weather components

This article shares with you how to use Vue to load weather components for your reference. The specific content is as follows

First, we enter the China Weather Network to generate a piece of code

Set the weather style as needed

Copy and modify the generated code into vue

Modify the script import to Vue's dynamic import method

<template>
    <div id="weater">
        <div id="weather-view-he" ref="weather"></div>
        <remote-script src="script src in the weather network generated code"></remote-script>
    </div>
</template>
<script>
window.WIDGET = {ID: '123456'}; // Add window in front of WIDGET, otherwise this variable cannot be read import Vue from 'vue'
Vue.component('remote-script', { // vue dynamically generates script (used as a component in html)
    render: function (createElement) {
        var self = this;
        return createElement('script', {
            attrs: {
                type: 'text/javascript',
                src: this.src
            },
            on: {
                load: function (event) {
                    self.$emit('load', event);
                },
                error: function (event) {
                    self.$emit('error', event);
                },
                readystatechange: function (event) {
                    if (this.readyState == 'complete') {
                        self.$emit('load', event);
                    }
                }
            }
        });
    },
    props: {
        src: {
            type: String,
            required: true
        }
    }
})
export default {
    name:"Weather",
    data(){
        return {
           
        }
    },
}
</script>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue implements a small weather forecast application
  • Vue implements weather forecast function
  • How to use webSocket to update real-time weather in Vue
  • Vue Getting Started with Weather Forecast

<<:  Understanding and application analysis of mysql pessimistic locking and optimistic locking

>>:  Detailed explanation on how to deploy H5 games to nginx server

Recommend

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

How to load Flash in HTML (2 implementation methods)

First method : CSS code: Copy code The code is as ...

HTML CSS3 does not stretch the image display effect

1. Use the transform attribute to display the ima...

How to use react-color to implement the front-end color picker

background We can use react-color to implement th...

How to use Docker to build a pypi private repository

1. Construction 1. Prepare htpasswd.txt file The ...

Advantages and disadvantages of common MySQL storage engines

Table of contents View all storage engines InnoDB...

How to create Apache image using Dockerfile

Table of contents 1. Docker Image 2. Create an in...

Detailed example of concatenating multiple fields in mysql

The MySQL query result row field splicing can be ...

my.cnf (my.ini) important parameter optimization configuration instructions

MyISAM storage engine The MyISAM storage engine i...

What does input type mean and how to limit input

Common methods for limiting input 1. To cancel the...