生成一个vue随机生成
时间: 2023-03-31 11:00:27 浏览: 134
我可以为您提供一个生成随机Vue组件的代码示例:
<template>
<div>
<h1>{{ title }}</h1>
<p>{{ content }}</p>
</div>
</template>
<script>
export default {
data() {
return {
title: '',
content: ''
}
},
created() {
this.title = this.generateRandomTitle()
this.content = this.generateRandomContent()
},
methods: {
generateRandomTitle() {
const titles = ['Hello World', 'Welcome to Vue', 'Vue is Awesome']
return titles[Math.floor(Math.random() * titles.length)]
},
generateRandomContent() {
const contents = ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.', 'At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident.']
return contents[Math.floor(Math.random() * contents.length)]
}
}
}
</script>
<style scoped>
h1 {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
p {
font-size: 16px;
line-height: 1.5;
}
</style>
阅读全文