在python中,<template>
<div class="container" id="project-edit">
<section class="client-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingClient">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingClient">
<!-- SNIP -->
</fieldset>
<div class="buttons">
<button v-if=!isEditingClient id="edit-client" v-on:click="editMode">edit</button>
<button v-if=isEditingClient v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingClient v-on:click="post">save changes</button>
</div>
</section><!-- END .client-data -->
<section class="gig-data">
<!-- show static if editMode FALSE -->
<dl v-if="!isEditingGig">
<!-- SNIP-->
</dl>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="isEditingGig">
<!-- SNIP-->
</fieldset>
<div class="buttons">
<button v-if=!isEditingGig id="edit-gig" v-on:click="editMode">edit</button>
<button v-if=isEditingGig v-on:click="cancelEdit">cancel</button>
<button v-if=isEditingGig v-on:click="post">save changes</button>
</div>
</section><!-- END .gig-data -->
<section class="contacts-wrapper">
<!-- show static if editMode FALSE -->
<dl>
<dt>contacts:</dt>
<dd>
<li v-for="(contact, ix) in project.contacts">
<!-- show orig data if editMode FALSE -->
<div v-if="!contact.editingContact">
{{ contact.name }} ({{ ix }})<br />
{{ contact.title }}<br />
{{ contact.email }}<br />
{{ contact.phone }}
<div class="buttons">
<button v-if=!contact.editingContact id="edit-contact" v-on:click="contact.editingContact = true">edit</button>
</div>
</div>
<!-- show FORM if editMode TRUE -->
<fieldset v-if="contact.editingContact">
<!-- SNIP: FORM ... -->
<div class="buttons">
<!-- I realize that the v-if attributes are not necessary here -->
<button v-if=contact.editingContact v-on:click="contact.editingContact = false">cancel</button>
<button v-if=contact.editingContact v-on:click="post">save changes</button>
</div>
</fieldset>
</li>
</dd>
</dl>
</section>
</div>
</template>
<script>
export default {
props: [ "projectID" ],
components: {
},
data () {
return {
id: this.$route.params.id,
title: "Edit Project",
subtitle: "ID: " + this.$route.params.id,
project: {},
contactInfo: {},
workLocation: true,
submitted: false,
isEditingClient: false,
isEditingGig: false,
}
}, // data
created: function() {
this.$http.get("https://xyz.dataworld.com/projects/" + this.id + ".json")
.then(data => data.json())
.then(data => {
for (let contact of data.contacts) {
this.$set(contact, 'editingContact', false)
}
this.project = data;
})
}, // created
methods: {
addContactInfo: function(e) {
e.preventDefault();
this.projectID = this.id;
this.project.contacts.push(this.contactInfo);
this.contactInfo = {};
},
editMode: function(e) {
const buttonID = e.currentTarget.id;
switch (buttonID) {
case "edit-client":
this.isEditingClient = !this.isEditingClient;
break;
case "edit-gig":
this.isEditingGig = !this.isEditingGig;
break;
default:
}
},
editContact: function(e) {
},
cancelEdit: function() {
this.isEditingClient = false;
this.isEditingGig = false;
},
post: function() {
console.log(this.project);
this.$http.post("https://sr-giglog.firebaseio.com/projects.json", this.project)
.then(function(data){
this.submitted = true;
}
)} // post function
} // methods
}
</script>
相当于pow(x,y,z)
,前者比后者更有效。但为什么它有用呢?在哪个上下文中,通常需要计算这样的数量(或者至少通常足以让python开发人员将其包含在语言中)?