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 moment.js time and date processing

Monday to Sunday time format conversion (Y --- ye...

Four practical tips for JavaScript string operations

Table of contents Preface 1. Split a string 2. JS...

Complete steps to install MySQL 5.5 on CentOS

Table of contents 1. Preparation before installat...

A brief discussion on Nginx10m+ high concurrency kernel optimization

What is high concurrency? The default Linux kerne...

Detailed explanation of command to view log files in Linux environment

Table of contents Preface 1. cat command: 2. more...

How to create an index on a join table in MySQL

This article introduces how to create an index on...

How to use Dockerfile to build images in Docker

Build the image Earlier we used various images fo...

Docker network principles and detailed analysis of custom networks

Docker virtualizes a bridge on the host machine. ...

MySQL series: Basic concepts of MySQL relational database

Table of contents 1. Basic Concepts 2. Developmen...

Summary of MySQL password modification methods

Methods for changing passwords before MySQL 5.7: ...

Use of JavaScript sleep function

Table of contents 1.sleep function 2. setTimeout ...

Analysis of MySQL user management operation examples

This article describes the MySQL user management ...

Vue achieves seamless carousel effect

This article shares the specific code of Vue to a...