提示:vue2插件
文章目录
文章目录
前言
@lucky-canvas/vue
一、查看nodejs版本
node -v
二、创建项目
1、安装插建
npm install @lucky-canvas/vue --save
2、目录结构
3、引用main.js
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import VueLuckyCanvas from '@lucky-canvas/vue';
Vue.use(VueLuckyCanvas);
Vue.config.productionTip = false
new Vue({
render: h => h(App),
router
}).$mount('#app')
4、配置路由src/router/index.js
import Vue from 'vue';
import Router from 'vue-router';
import LuckyWheel from '@/components/LuckyWheel.vue';
import LuckyGrid from '@/components/LuckyGrid.vue';
import SlotMachine from '@/components/SlotMachine .vue';
Vue.use(Router);
const routes = [
{
path: '/', component: LuckyWheel },
{
path: '/lucky-wheel', component: LuckyWheel },
{
path: '/lucky-grid', component: LuckyGrid },
{
path: '/slot-machine', component: SlotMachine },
]
export default new Router({
routes })
三、大转盘
1、src/components/LuckyWheel.vue
<template>
<div class="lucky_wheel">
<h1>LuckyWheel页面</h1>
<template>
<LuckyWheel
ref="myLucky"
width="400px"
height="400px"
:prizes="prizes"
:blocks="blocks"
:buttons="buttons"
@start="startCallback"
@end="endCallback"
/>
</template>
</div>
</template>
<script>
export default {
name: 'LuckyWheel1',
data () {
return {
//转盘背景
blocks: [
{
padding: '40px', //可旋转区域与转盘边缘的距离
background: '#eee', //转盘背景色
//转盘背景图
imgs:[
{
src:require('@/assets/LuckyWheel.png'), //图片url
top:'0', //图片距顶部距离
width:'400px', //图片宽
height:'400px', //图片高
}
],
}
],
// 扇形数组
prizes: [
//单个扇形
{
//奖品文字
fonts: [
{
text: '苹果', //文字
top: '10%', //文字距顶部距离
fontColor:'#f00', //文字颜色
fontSize:'16px', //文字大小
fontStyle:'微软雅黑', //字体
fontWeight:'500', //加粗
lineHeight:'16px', //行高
wordWrap:true, //换行
lineClamp:2, //2行,剩下的...
wordWrap:true, //换行
}
],
//奖品图
imgs:[
{
src:'https://img95.699pic.com/xsj/1s/5e/0g.jpg%21/fh/300', //图片url
top:'30%', //图片距顶部距离
width:'60px', //图片宽
height:'60px', //图片高
}
],
background: '#FFF402', //扇形背景色
range:10, //当前prize.range/所有prize中range总和
},
{
fonts: [{
text: '橘子', top: '10%' }], background: '#76C5F0' },
{
fonts: [{
text: '香蕉', top: '10%' }], background: '#2A1570' },
{
fonts: [{
text: '葡萄', top: '10%' }], backgro