项目作者: andrewvasilchuk

项目描述 :
Vue.js derective for setting an aspect ratio
高级语言: TypeScript
项目地址: git://github.com/andrewvasilchuk/v-aspect-ratio.git
创建时间: 2019-03-07T10:48:57Z
项目社区:https://github.com/andrewvasilchuk/v-aspect-ratio

开源协议:MIT License

下载


v-aspect-ratio

Vue.js directive for setting an aspect ratio

BuildStatus
Version
Bundle Size
Codacy Badge
Total alerts
Language grade: JavaScript
codecov
Downloads
LastCommit
License
MadeWithVueJs.com shield

1.x documentation can be found here.

Computer screens with different aspect ratios

Installation

Via NPM

  1. $ npm install v-aspect-ratio --save

Via Yarn

  1. $ yarn add v-aspect-ratio

Directly in browser

  1. <script src="https://unpkg.com/v-aspect-ratio"></script>

Initialization

As a global plugin

It must be called before new Vue()

  1. import Vue from 'vue'
  2. import AspectRatio from 'v-aspect-ratio'
  3. Vue.use(AspectRatio)

As a global directive

  1. import Vue from 'vue'
  2. import { directive } from 'v-aspect-ratio'
  3. Vue.directive('aspect-ratio', directive)

As a local directive

  1. import { directive } from 'v-aspect-ratio'
  2. export default {
  3. name: 'YourAwesomeComponent',
  4. directives: {
  5. 'aspect-ratio': directive,
  6. },
  7. }

As a Nuxt.js SSR directive

  1. // nuxt.config.js
  2. const {
  3. directive,
  4. } = require('v-aspect-ratio/dist/v-aspect-ratio.ssr.common.js')
  5. module.exports = {
  6. // ...
  7. render: {
  8. bundleRenderer: {
  9. directives: {
  10. 'aspect-ratio': directive,
  11. },
  12. },
  13. },
  14. // ...
  15. }

Directly in browser

  1. <!-- As a global directive -->
  2. <script>
  3. Vue.use(VAspectRatio.default)
  4. new Vue({
  5. // ...
  6. })
  7. </script>
  8. <!-- As a local directive -->
  9. <script>
  10. new Vue({
  11. // ...
  12. directives: { 'aspect-ratio': VAspectRatio.directive },
  13. // ...
  14. })
  15. </script>

Usage

  1. <template>
  2. <div>
  3. <div v-aspect-ratio="'16:9'"></div>
  4. <div v-aspect-ratio="'4:3'"></div>
  5. </div>
  6. </template>

Demo

Demo

Demo

Tests

jest and @vue/test-utils is used for unit tests.

You can run unit tests by running the next command:

  1. npm run test

Development

  1. Clone this repository
  2. Install the dependencies running yarn install or npm install command
  3. Start a development server using npm run dev command

Build

To build the production ready bundle simply run npm run build:

After the successful build the following files will be generated in the dist folder:

  1. ├── plugin
  2. ├── index.d.ts
  3. ├── directive.d.ts
  4. ├── helpers.d.ts
  5. ├── index.d.ts
  6. ├── v-aspect-ratio.common.js
  7. ├── v-aspect-ratio.esm.js
  8. ├── v-aspect-ratio.js
  9. ├── v-aspect-ratio.min.js
  10. ├── v-aspect-ratio.ssr.common.js
  11. ├── v-aspect-ratio.ssr.esm.js
  12. ├── v-aspect-ratio.ssr.js
  13. ├── v-aspect-ratio.ssr.min.js

License

MIT