npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amap-js-vue

v0.1.0

Published

`amap-js-vue` 是基于 Vue.js 和 高德地图 AMap JavaScript API 的地图组件

Downloads

3

Readme

amap-js-vue

Build Status npm version npm downloads npm downloads JS Gzip Size npm license

amap-js-vue 是基于 Vue.js 和 高德地图 AMap JavaScript API 的地图组件。

开发者在使用高德地图API更加得心应手。

安装

npm:

$ npm install amap-js-vue --save

Yarn:

$ yarn add amap-js-vue

引入组件

方式一.导入所有组件

import Vue from 'vue';
import AMapJS from 'amap-js-vue';
import 'amap-js-vue/lib/index.css';

// 安装并添加配置
// 如果在添加配置可以调用 AMapJS.config({});
Vue.use(AMapJS, {
  AMap: 'https://webapi.amap.com/maps?key=您申请的高德key值&v=1.4.15&plugin=[]',
  AMapUI: 'https://webapi.amap.com/ui/1.0/main-async.js', // default: false
});

方式二.手动按需引入组件

在不使用插件的情况下,可以手动引入需要的组件

import config from 'amap-js-vue/config';
import Map from 'amap-js-vue/lib/map';
import 'amap-js-vue/lib/map/style';

// 添加配置
config({
  AMap: 'https://webapi.amap.com/maps?key=您申请的高德key值&v=1.4.15&plugin=[]',
  AMapUI: 'https://webapi.amap.com/ui/1.0/main-async.js', // default: false
});

方式三.自动按需引入组件 (推荐)

安装插件

npm i babel-plugin-import -D

// 对于使用 babel7 的用户,可以在 babel.config.js 中配置
module.exports = {
  plugins: [
    ['import', {
      libraryName: 'amap-js-vue',
      libraryDirectory: 'es',
      style: true
    }, 'amap-js-vue']
  ]
};
// 接着你可以在代码中直接引入 Vant 组件
// 插件会自动将代码转化为方式二中的按需引入形式
import { config, Map } from 'amap-js-vue';

// 添加配置
config({
  AMap: 'https://webapi.amap.com/maps?key=您申请的高德key值&v=1.4.15&plugin=[]',
  AMapUI: 'https://webapi.amap.com/ui/1.0/main-async.js', // default: false
});

快速上手

地图组件

<template>
  <am-map :init-map-options="options" style="width: 300px; height: 300px;"></am-map>
</template>

<script>
export default {
  data() {
    return {
      options: {
        resizeEnable: true, //是否监控地图容器尺寸变化
        zoom: 11, //初始化地图层级
        center: [116.397428, 39.90923] //初始化地图中心点
      },
    };
  },
};
</script>

自定义组件

开发者根据需要定制组件满足自身需求。这里提供一个 createComponent 方法来创建组件;

my-component.vue

<template>
  <div>{{ msg }}</div>
</template>

<script>
import { createComponent } from 'amap-js-vue';

export default createComponent({
  name: 'AmMyComponent',
  data() {
    return {
      msg: 'Hello, MyComponent',
    };
  },
  created() {
    console.log('created');
  },
  mounted() {
    console.log('mounted');
  },
  ready() {
    console.log('ready');
    const { AMap, AMapUI, map } = this.$maproot;
  },
  destroyed() {
    console.log('destroyed');
  },
});
</script>

<style></style>

以上是个简单当例子。 由于高德地图API的特殊性,所以除了Vue自身的Options API以外主要扩展了一个关键的生命周期ready, 它的主要特性是在地图 API 和 map 实例都创建好并且自身组件mounted生命周期之后所调用。

$maproot: 是指向 am-map 组件实例。包含 AMapAMapUI(可选)、 map

链接

AMap JavaScript API

AMap UI JavaScript API

License

Licensed under MIT

Copyright (c) 2019-present Derek Li